简体   繁体   English

未捕获的ReferenceError:未定义$(匿名函数)

[英]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.

相关问题 未捕获的ReferenceError:函数未定义(匿名函数) - Uncaught ReferenceError: function not defined (anonymous function) 未捕获的ReferenceError:未定义ajax(匿名函数) - Uncaught ReferenceError: ajax is not defined (anonymous function) 未捕获的ReferenceError:未定义foobar(匿名函数) - Uncaught ReferenceError:foobar is not defined (anonymous function) 未捕获的ReferenceError:未定义msgbox(匿名函数) - Uncaught ReferenceError: msgbox is not defined (anonymous function) 未捕获的ReferenceError:未定义rotationAnimation(匿名函数) - Uncaught ReferenceError: rotateAnimation is not defined(anonymous function) 未捕获的ReferenceError:未定义stopme(匿名函数) - Uncaught ReferenceError: stopme is not defined (anonymous function) 未捕获的ReferenceError:未定义角度(匿名函数) - Uncaught ReferenceError: angular is not defined (anonymous function) 未被捕获的ReferenceError:未定义loadNext(匿名函数) - Uncaught ReferenceError: loadNext is not defined (anonymous function) 未捕获的 ReferenceError: _ is not defined at<anonymous> :1:1(不是 jQuery) - Uncaught ReferenceError: _ is not defined at <anonymous>:1:1 (Not jQuery) JavaScript:未捕获的ReferenceError:未定义define_Logout(匿名函数) - JavaScript: Uncaught ReferenceError: confirm_Logout is not defined (anonymous function)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM