为什么这段代码会抛出

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

以前什么时候还好?

$(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>

当前回答

在我的案例中,这是一个拼写错误,我忘记了反斜杠,并且错误地引用了源代码。

在src=“/scripts/jquery.js”之前

在src=“scripts/jquery.js”之后

其他回答

在我的案例中,这是一个拼写错误,我忘记了反斜杠,并且错误地引用了源代码。

在src=“/scripts/jquery.js”之前

在src=“scripts/jquery.js”之后

多!我在标记中混合了引号,导致jquery引用中断。通过在Chrome中进行检查,我可以看到文件没有正确链接。

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

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

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

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

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

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

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

我也有类似的问题。我的测试服务器使用“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工作的人有所帮助。