[英]Uncaught ReferenceError: $ is not defined(anonymous function)
I get this from console, Uncaught ReferenceError: $ is not defined(anonymous function) @ function.js:2 .. 我从控制台得到这个, Uncaught ReferenceError:$ is not defined(anonymous function)@ function.js:2 ..
this is my js code 这是我的js代码
$(function() {
mobileNav();
});
function mobileNav() {
$('.mobile-btn').on('click', function(){
var status = $(this).hasClass('is-open');
if(status){ $('.mobile-nav-toggle, .mobile-btn').removeClass('is-open'); }
else { $('.mobile-nav-toggle, .mobile-btn').addClass('is-open'); }
});
}
on local host everythings gone well, but on the server i got this js error.. 在本地主机上一切正常,但在服务器上我收到此js错误。
<script src="/js/jquery-2.1.4.min.js" type="text/javascript"></script> <script src="/js/function.js" type="text/javascript"></script>
$ is not defined error occur if your JQuery library is not loaded. 如果未加载JQuery库,则$未定义错误发生。
Please add the jquery library or if you have added the jquery library then check the path you have provided. 请添加jquery库,或者如果已添加jquery库,请检查提供的路径。
You have not added jquery in your code: 您尚未在代码中添加jquery:
add this line if you want to use remote jquery CDN. 如果要使用远程jquery CDN,请添加此行。 I recommend to have a local copy on your server but if you want to use remote one i can suggest you the below one. 我建议在您的服务器上有一个本地副本,但是如果您要使用远程副本,我可以建议您使用以下副本。
<script src = "https://code.jquery.com/jquery-2.1.4.min.js" ></script>
Edit 编辑
Also there might be an conflict with other jquery plugins if you are using jquery in your code, best way to do check it is by removing one by one plugin and see where it works. 另外,如果您在代码中使用jquery,则可能会与其他jquery插件发生冲突,最好的检查方法是逐个删除插件并查看其工作原理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.