jQuery is not defined error

戏子无情 提交于 2021-01-29 16:00:57

问题


Error in Jquery

In view file (index.php)

 <script type="text/javascript" src="crosscut.js" ></script> 
 <script src="jquery-ui.min.js" type="text/javascript"></script>
 <script type="text/javascript" src="mod-min.js" ></script>
 <script type="text/javascript" src="jquery-min.js" ></script>

In Javascript file

$(document).ready(function() {
    $('#crossline').css('background-color','blue');
});

button = function() {
   // other code
}

I have included jquery-min.js in script and it is loaded on page loading. jquery-min.js all code loaded while inspecting through firebug .

If file may be corrupted ,So I tried live path of "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" still not works.

If calling javascript function uses jquery works fine if ready function not set .


回答1:


You're not providing much info, but one issue you have is that you're loading jQueryUI before you load jQuery.

Any other files that rely on jQuery must be loaded after jQuery as well.

    <!-- this one first! -->
 <script type="text/javascript" src="jquery-min.js" ></script>

 <script type="text/javascript" src="crosscut.js" ></script> 
 <script src="jquery-ui.min.js" type="text/javascript"></script>
 <script type="text/javascript" src="mod-min.js" ></script>



回答2:


if you are using jQuery.js load jQuery.js first and then other js Sequence also important.

    <script src="js/jQuery.js" type="text/javascript"></script>      
    <script src="js/jQuery.alert.js" type="text/javascript"></script>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/CustomerSummary.js"></script>
    <link rel="stylesheet" href="css/style.css" type="text/css"></link>
    <link rel="stylesheet" href="css/style_new.css" type="text/css"></link>


来源:https://stackoverflow.com/questions/8373357/jquery-is-not-defined-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!