如何修复jQuery库中的“jQuery未定义”错误?

时间:2022-01-08 08:58:37

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? 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). I wasn't getting this error the other day -- even reverted the code to make sure.

第一个问题是获得与自身相关的javascript错误?这似乎不太可能。这看起来像是一个错误的方向(真正的错误在其他地方)。我该怎么做才能解决这个问题呢?页面上的JS错误看起来有点不专业(至少对其他开发人员来说是这样)。前几天我并没有犯这个错误——我甚至重新修改了代码以确保。

2 个解决方案

#1


22  

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>

#2


1  

jQuery UI doesn't include the standard jQuery library by default. You'll need to add a <script> tag to include the standard jQuery library before including any plugins that use it.

默认情况下,jQuery UI不包含标准jQuery库。您需要添加一个

#1


22  

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>

#2


1  

jQuery UI doesn't include the standard jQuery library by default. You'll need to add a <script> tag to include the standard jQuery library before including any plugins that use it.

默认情况下,jQuery UI不包含标准jQuery库。您需要添加一个