简体   繁体   English

$未定义,但jQuery在Wordpress中定义

[英]$ not defined but jQuery IS defined in Wordpress

What might cause Firefox to tell me $ is not defined, but using 'jQuery' works as expected. 没有定义可能导致Firefox告诉我$的原因,但是使用'jQuery'的效果符合预期。

I'm on Wordpress 3.4 and Wordpress comes packaged with jQuery. 我使用的是Wordpress 3.4,而Wordpress随附于jQuery。 Is it something specific to Wordpress? 它是特定于Wordpress的吗?

jQuery.noConflict() has been called. jQuery.noConflict()已被调用。 To resolve this with a minimum amount of code change do this. 要用最少的代码更改来解决此问题,请执行此操作。

Before: 之前:

$("your").code(function () {
  $("that").uses($.all("over").the("place"));
});

After: 后:

(function ($) {
  $("your").code(function () {
    $("that").uses($.all("over").the("place"));
  });
})(jQuery);

jQuery在WordPress中以noConflict模式在文档状态下工作: http ://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers

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

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