jQuery Javascript 运行时错误:$ 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17637870/
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-26 19:27:32  来源:igfitidea点击:

Javascript Runtime error: $ is undefined

javascriptjqueryasp.net

提问by Ajay

I have added script in my Default.aspxpage. I am getting following error. Error

我在我的Default.aspx页面中添加了脚本。我收到以下错误。 错误

回答by Marcelo Cantos

$is defined by jQuery, which you probably haven't referenced. A simple way to get it is to add one of the CDN urls to your template HTML:

$由 jQuery 定义,您可能没有引用。获取它的一种简单方法是将其中一个 CDN 网址添加到您的模板 HTML 中:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

回答by CodingIntrigue

You need to include jQuery: http://learn.jquery.com/about-jquery/how-jquery-works/

您需要包含 jQuery:http: //learn.jquery.com/about-jquery/how-jquery-works/

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Demo</title>
    **<script src="jquery.js"></script>**
</head>
<body>
  ...
</body>
</html>

回答by taylorsabell

I had the same problem, but did have a correct reference to jQuery.

我遇到了同样的问题,但确实对 jQuery 有正确的引用。

I solved it by referencing jQuery beforeany other scripts. In your case, it would look like this:

我通过任何其他脚本之前引用 jQuery 来解决它。在你的情况下,它看起来像这样:

<script src= "scripts/jquery-ui.js" />
<script src= "scripts/JavaScript_scroll.js" />

Hope this helps anyone else with a similar issue.

希望这可以帮助其他有类似问题的人。

回答by Abdul Khaliq

I had the Same Problem as that $ is Unidentified, After a long struggle, I come to know that there is some thing HTML coder error in Master Page, So it worked fine when i include the Jquery files directly in Content pageenter image description here

我遇到了与 $ 身份不明的相同问题,经过长时间的斗争,我知道母版页中存在一些 HTML 编码器错误, So it worked fine when i include the Jquery files directly in Content page在此处输入图片说明

回答by mok

(For others who may face the same problem as OP's)
I had the same problem, but the reason was that I was trying to load my jQueryscript before loading the jQuerylibrary itself. In other words, make sure that you first add this line:

(对于可能面临与 OP 相同问题的其他人)
我遇到了同样的问题,但原因是我试图jQuery在加载jQuery库本身之前加载我的脚本。换句话说,请确保您首先添加以下行:

<script src="Scripts/jquery-{version}.min.js"></script>

before adding

添加前

<script src="Scripts/JavaSript_scroll.js"></script>