javascript 参考错误:找不到变量:$
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9626455/
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
ReferenceError: Can't find variable: $
提问by Filuren
I've come across a fairly normal problem, but I can't solve it.
I tried to fix the jQuery scripts dozens of times, but it just won't work. It suddenly just stopped working after a few weeks.
我遇到了一个相当正常的问题,但我无法解决它。
我试图修复 jQuery 脚本几十次,但它就是行不通。几周后它突然停止工作。
I am positive that I included the jQuery script, and I did test if the site was alive.
However, it seems like my browser or server ain't loading it with the site load...
我很肯定我包含了 jQuery 脚本,并且我确实测试了该站点是否还活着。
但是,似乎我的浏览器或服务器没有在站点加载时加载它......
It load my Google Analytics script perfectly fine, but it won't load the jQuery script. Even if I host i myself.
它可以完美地加载我的 Google Analytics 脚本,但它不会加载 jQuery 脚本。即使我自己主持。
This is the code
这是代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="scripts/ganalytics.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('img').hover(function(){
$(this).data('jpg', $(this).attr('src'));
$(this).attr('src',$(this).data('gif'));
},
function(){
$(this).attr('src',$(this).data('jpg'));
});
});
</script>
Here, it produces the error on line #5 or line #15 in my website
I am lost here, how do I fix this? It was working great, and then suddenly, boom, out of nothing, it stopped working. Have been trying to fix this, but I can't figure it out.
我在这里迷路了,我该如何解决这个问题?它工作得很好,然后突然,砰的一声,从无到有,它停止了工作。一直试图解决这个问题,但我无法弄清楚。
Cheers, thanks for reading
干杯,感谢阅读
EDIT: Included a JSFiddleas it was requested in the comments. Hope I included the necessary code.
编辑:按照评论中的要求包含了一个JSFiddle。希望我包含了必要的代码。
回答by Shea
Replace all "$" with "jQuery". If that works: jQuery.noConflict()
用“jQuery”替换所有“$”。如果可行: jQuery.noConflict()