为什么这段代码会抛出

未捕获引用错误:未定义$

以前什么时候还好?

$(document).ready(function() {
    $('#tabs > ul').tabs({ fx: { opacity: 'toggle' } });
    $('#featuredvid > ul').tabs();
});

选项卡中的结果不再关闭。

jQuery在头中被引用:

<script language="JavaScript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/js/sprinkle.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/js/jquery-1.2.6.min.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo get_option('siteurl') ?>/js/jquery-ui-personalized-1.5.2.packed.js"></script>

当前回答

我在尝试运行不同的web套接字示例时遇到了这个问题。

将浏览器指向“”时http://localhost:8080/'我收到了这个错误,但正好指向'http://localhost:8080/index.html'没有给出任何错误,因为在'index.html'中,所有都完全正常-jquery在使用$..之前已包含。。

不知为何,自动转发到index.html没有完全工作

其他回答

我也有类似的问题。我的测试服务器使用“http”时工作正常。然而,它在具有SSL的生产中失败。

因此,在生产中,我添加了“HTPPS”而不是“HTTP”,在测试中,我保持了“HTTP”。

测试:

wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', array(), null, false );

wp_register_script( 'custom-script', plugins_url( '/js/custom.js', __FILE__ ), array( 'jquery' ) );

生产:

wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', array(), null, false );

wp_register_script( 'custom-script', plugins_url( '/js/custom.js', __FILE__ ), array( 'jquery' ) );

希望这对正在wordpress工作的人有所帮助。

在使用$或jQuery的脚本之前添加jQuery库,以便在脚本中标识$。删除头上的标记脚本并结束bady

 <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

然后首先在jsadd文件中编写脚本

/*global $ */
$(document).ready(function(){  });

这就是我解决这个问题的原因。最初我去了谷歌,复制并粘贴了他们建议的jQuery片段到他们的CDN页面上:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

该片段在src属性中不包含HTTP:或HTTPS:,但我的浏览器FireFox需要它,所以我将其更改为:编辑:这也适用于我的谷歌Chrome

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

然后它奏效了。

如果您在.Net中执行此操作,并且正确引用了脚本文件,并且jQuery看起来很好,请确保您的用户可以访问脚本文件。我正在处理的项目(一名同事)的web.config拒绝匿名用户访问。匿名用户可以访问我正在处理的页面,因此他们无权访问脚本文件。将以下内容放到web.config中,一切正常:

  <location path="Scripts">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

如果是wordpress,可能需要更改

$(document).ready(function() {

to

jQuery(document).ready(function($){

或添加

var $ = jQuery;

之前

$(document).ready(function() {