Javascript 未捕获的 ReferenceError: $ 未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6454694/
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
Uncaught ReferenceError: $ is not defined
提问by Bar?? Velio?lu
I am trying to reference to jquery library to provide intellisense on another javascript file. But I got error such as "Uncaught ReferenceError: $ is not defined"
我正在尝试引用 jquery 库以在另一个 javascript 文件上提供智能感知。但我得到了错误,例如"Uncaught ReferenceError: $ is not defined"
/// <reference path="jquery.min.js" />
$(document).ready(function () {
alert("alert");
});
EDITED
已编辑
Note: I have only one jquery library. Any other libraries have not been included.
注意:我只有一个 jquery 库。没有包括任何其他库。
回答by George Cummins
Javascripts (including jQuery) are loaded with the following syntax:
Javascript(包括 jQuery)使用以下语法加载:
<script type="text/javascript" src="url_to_your_script" />
Please review your HTML document to ensure that you have a line like that one, and that the src
attribute points to the jQuery script's location. You can test it by copying the contents of the src attribute and pasting it in your browser's address bar.
请检查您的 HTML 文档以确保您有这样一行,并且该src
属性指向 jQuery 脚本的位置。您可以通过复制 src 属性的内容并将其粘贴到浏览器的地址栏中来测试它。
回答by Hooray Im Helping
As silly as it sounds, make sure that your script tags have a matching ending </script>
tag. If you're missing one, it will mess up the loading of any scripts after it.
尽管听起来很愚蠢,但请确保您的脚本标签具有匹配的结束</script>
标签。如果你错过了一个,它会搞乱它之后的任何脚本的加载。
回答by Fakhr Alam
mine same problem solved by replacing
我的同样问题通过更换解决
<script src="folderOnMyPc/local/jquery.js">
with
和
<script src="http://code.jquery.com/jquery-latest.min.js">
回答by deadalnix
You probably did not included jQuery properly, or use the noConflict mode : http://api.jquery.com/jQuery.noConflict/
您可能没有正确包含 jQuery,或者使用 noConflict 模式:http://api.jquery.com/jQuery.noConflict/
回答by OsQu
You might use some other libraries that hide the $-function You can use jQuery as a substance to $. In your example:
您可能会使用其他一些隐藏 $-function 的库,您可以使用 jQuery 作为 $ 的实体。在你的例子中:
/// <reference path="jquery.min.js" />
jQuery(document).ready(function () {
alert("alert");
});
More info of using jQuery with other librarires can be found here.
回答by geekgugi
All the .js files must be accessible by the server. Just check the ownership and permission of the file.
服务器必须可以访问所有 .js 文件。只需检查文件的所有权和权限。
回答by Raj
Try to get query from a CDN like,
尝试从 CDN 获取查询,例如,
For other CDNs http://jquery.com/download/
对于其他 CDN http://jquery.com/download/
Note: make sure the url's have 'https://' prefix
注意:确保 url 有“https://”前缀