未捕获的引用错误:$ 未定义
我试图引用 jquery 库来在另一个 javascript 文件上提供智能感知。但我收到了诸如 “Uncaught ReferenceError: $ is not Defined”之类的错误
/// <reference path="jquery.min.js" />
$(document).ready(function () {
alert("alert");
});
EDITED
注意:我只有一个 jquery 库。尚未包含任何其他库。
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"
/// <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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
Javascript(包括 jQuery)使用以下语法加载:
请检查您的 HTML 文档以确保您有这样的一行,并且
src
属性指向 jQuery 脚本的位置。您可以通过复制 src 属性的内容并将其粘贴到浏览器的地址栏中来测试它。Javascripts (including jQuery) are loaded with the following syntax:
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.尽管听起来很愚蠢,但请确保您的脚本标记具有匹配的结束
标记。如果您缺少一个,则会扰乱其后所有脚本的加载。
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.我的同样的问题通过替换
解决
mine same problem solved by replacing
with
您可能没有正确包含 jQuery,或者使用 noConflict 模式: http://api.jquery.com/ jQuery.noConflict/
You probably did not included jQuery properly, or use the noConflict mode : http://api.jquery.com/jQuery.noConflict/
您可能会使用一些其他隐藏 $ 函数的库您可以使用 jQuery 作为 $ 的实质。在您的示例中:
有关将 jQuery 与其他库一起使用的更多信息 可以在此处找到。
You might use some other libraries that hide the $-function You can use jQuery as a substance to $. In your example:
More info of using jQuery with other librarires can be found here.
我的问题通过交换 jquery 库和 jquery 脚本的链接位置得到解决。 jquery 库的链接必须位于脚本的链接之前。
My problem was solved by swapping of places of links to jquery library and to jquery script. A link to jquery library must be before the link to a script.
所有 .js 文件必须可由服务器访问。只需检查文件的所有权和权限即可。
All the .js files must be accessible by the server. Just check the ownership and permission of the file.
尝试从 CDN 获取查询,例如
对于其他 CDN
http://jquery.com/download/
注意:确保网址有“https://”前缀
Try to get query from a CDN like,
For other CDNs
http://jquery.com/download/
Note: make sure the url's have 'https://' prefix