C# JavaScript 运行时错误:“$”未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16946547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:12:21  来源:igfitidea点击:

JavaScript runtime error: '$' is undefined

javascriptc#jqueryvisual-studio-2012

提问by user1408956

Can someone help with this error in my code. I get this error when i start the website in Internet Explorer:

有人可以帮助解决我的代码中的这个错误。在 Internet Explorer 中启动网站时出现此错误:

JavaScript runtime error: '$' is undefined

JavaScript 运行时错误:“$”未定义

This is the code please help me what i need to change in the java script?

这是代码,请帮助我在java脚本中需要更改什么?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<style type="text/css">
    div.world_map_container #transparent_map {
        border: medium none;
        height: auto;
        position: absolute;
        width: auto;
        z-index: 30;
    }

    ul li {
        display: none;
        position: absolute;
        text-indent: -9999px;
        z-index: 20;
    }


    #home_resen {
        background: url("Sliki/resen.gif") no-repeat;
        height: auto;
        right: 0;
        top: 0;
        width: auto;
    }

    #home_skopje {
        background: url("Sliki/skopje.gif") no-repeat;
        height: auto;
        right: 0;
        top: 0;
        width: auto;
    }

    #home_kocani {
        background: url("Sliki/kocani.gif") no-repeat;
        height: auto;
        right: 0;
        top: 0;
        width: auto;
    }
  </style>
  </head>
  <body>
  <form id="form1" runat="server">
    <div class="world_map_container">
        <img src="Sliki/map.jpg" usemap="#the_world_map" id="transparent_map" />
        <map name="the_world_map" id="the_world_map">
            &nbsp;<area shape="poly" coords="167,335,168,321,166,318,161,313,156,308,148,308,146,304,143,302,137,301,136,293,133,283,130,277,127,273,127,270,129,266,133,261,133,253,132,248,128,242,124,240,121,240,118,243,114,248,108,254,100,258,94,261,92,261,91,268,87,274,83,279,81,281,81,286,81,291,81,295,75,298,69,304,67,308,66,316,69,318,79,319,86,319,88,321,91,324,94,326,100,325,102,322,103,317,100,315,95,314,88,312,85,308,87,303,90,300,94,297,98,294,104,293,109,293,113,295,119,303,124,311,127,318,130,327,131,335,132,338,135,336,140,332,144,331,148,331,151,333,155,336,162,336,167,335" href="Default2.aspx" id="area_resen" alt="Resen" />
            <area shape="poly" coords="171,45,167,47,161,47,162,50,167,50,167,53,164,55,157,64,161,68,169,88,172,89,175,102,175,105,179,105,180,109,187,116,187,118,202,121,202,124,212,124,216,121,216,116,245,116,253,113,255,110,254,104,253,103,259,103,265,104,269,105,272,103,272,95,274,90,277,87,282,86,285,84,287,78,288,76,280,75,274,74,270,72,265,67,263,63,257,63,254,60,251,57,250,56,247,57,241,56,237,55,234,52,229,49,227,44,227,38,231,35,233,33,231,31,226,29,225,28,225,21,220,20,216,22,213,24,212,26,210,28,207,28,205,26,202,26,200,28,199,31,196,33,192,39,188,43,189,45,189,47,185,50,179,52,175,52,172,50,171,47,171,45" href="Default2.aspx" id="area_skopje" alt="Skopje" />
            <area shape="poly" coords="397,47,388,47,383,56,384,61,384,66,382,70,379,71,375,71,375,76,373,82,372,88,372,94,377,96,389,109,408,109,409,98,405,92,409,89,406,80,412,80,421,77,424,74,423,68,429,66,425,63,415,53,398,53,397,47" href="Default2.aspx" id="area_kocani" alt="Kocani" />
        </map>
        <ul>
            <li id="resen"><a href="#">resen</a></li>
            <li id="skopje"><a href="#">skopje</a></li>
            <li id="kocani"><a href="#">kocani</a></li>
        </ul>
    </div>
    <script type="text/javascript">
        $('.world_map_container area').each(function () {
            // Assigning an action to the mouseover event
            $(this).mouseover(function (e) {
                var country_id = $(this).attr('id').replace('area_', 'home_');
                $('#' + country_id).css('display', 'block');
            });

            // Assigning an action to the mouseout event
            $(this).mouseout(function (e) {
                var country_id = $(this).attr('id').replace('area_', 'home_');
                $('#' + country_id).css('display', 'none');
            });

        });
    </script>
</form>

采纳答案by karthikr

You have not included jqueryin your file.

您尚未包含jquery在您的文件中。

Something like this:

像这样的东西:

<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>

Or if you have it already in your source files, include it from there.

或者,如果您的源文件中已经有了它,请从那里包含它。

回答by matt-dot-net

Make sure you reference jquery with a script tag

确保您使用脚本标记引用 jquery

回答by Adil

You need to add jQueryin order to use jQuery, see how to use jQuery

需要添加jQuery才能使用jQuery,看jQuery的使用方法

<script src='http://code.jquery.com/jquery-latest.min.js' type='text/javascript'></script>

回答by DHIRAJ KATEKAR

I would suggest you to try this. Your internet explorer settings might not be allowing you to download the jquery files.

我建议你试试这个。您的 Internet Explorer 设置可能不允许您下载 jquery 文件。

  1. Click Internet Options.
  2. Switch to tab Security, and then click Custom level...
  3. Scroll down in the list of settings until you see the section Downloads.
  4. Set all download options in this section to Enabled.
  5. Click OK to save the settings.
  1. 单击 Internet 选项。
  2. 切换到安全选项卡,然后单击自定义级别...
  3. 在设置列表中向下滚动,直到看到“下载”部分。
  4. 将此部分中的所有下载选项设置为已启用。
  5. 单击确定以保存设置。

回答by Mtu

I have this error in IE 11 because I link to my Custom JQueryfile before linking to Jquerylibrary.

我在 IE 11 中有这个错误,因为我JQuery在链接到Jquery库之前链接到我的自定义文件。