简体   繁体   English

如何修复jquery库中的'jQuery is not defined'错误?

[英]how to fix 'jQuery is not defined' error in jquery library?

Rails fix : make sure <%= javascript_include_tag "application" %> is before any script loading so that jquery gets loaded first. Rails修复 :确保<%= javascript_include_tag "application" %>在任何脚本加载之前,以便首先加载jquery。

This seems really odd. 这看起来很奇怪。 When I load my page I get 2 js errors (in Chrome): 当我加载页面时,我得到2个js错误(在Chrome中):

jquery-ui.min.js:17  Uncaught ReferenceError: jQuery is not defined
jquery.blockUI.js:499  Uncaught ReferenceError: jQuery is not defined

Ok, that seems... odd. 好吧,这似乎......很奇怪。 So I look at my script includes. 所以我看看我的脚本包括。 My first two script includes on my page: 我的前两个脚本包括在我的页面上:

 <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
  <script src="http://bainternet-js-cdn.googlecode.com/svn/trunk/js/jQuery%20BlockUI%20Plugin/2.39/jquery.blockUI.js"></script>

So the first include is getting a javascript error related to itself? 所以第一个包括获取与自身相关的javascript错误? That seems unlikely. 这似乎不太可能。 This looks like a case of a misdirection error (the real error is somewhere else). 这看起来像是误导错误的情况(真正的错误在其他地方)。 What can I do to fix this? 我该怎么做才能解决这个问题? JS errors on pages look a little unprofessional (at least to other devs). 页面上的JS错误看起来有点不专业(至少对其他开发者而言)。 I wasn't getting this error the other day -- even reverted the code to make sure. 前几天我没有收到此错误 - 甚至还原了代码以确保。

your 你的

<script type="text/javascript" src="jquery.js"></script> 

needs to be called before jquery ui < script > tags. 需要在jquery ui <script>标记之前调用。

Should appear like this: 应该是这样的:

 <script type="text/javascript" src="jquery.js"></script> <-- put me here -->
 <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
 <script src="http://bainternet-js-cdn.googlecode.com/svn/trunk/js/jQuery%20BlockUI%20Plugin/2.39/jquery.blockUI.js"></script>

jQuery UI doesn't include the standard jQuery library by default. 默认情况下,jQuery UI不包含标准jQuery库。 You'll need to add a <script> tag to include the standard jQuery library before including any plugins that use it. 在包含使用它的任何插件之前,您需要添加<script>标记以包含标准jQuery库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM