类型错误:'undefined' 不是函数(评估 '$(document)') [英] TypeError: 'undefined' is not a function (evaluating '$(document)')
问题描述
- 我使用的是 WordPress 网站.
- 我在标题中包含了这个脚本.
当脚本加载时,我收到此错误:
When the script loads, I get this error:
TypeError: 'undefined' 不是函数(评估 '$(document)')
TypeError: 'undefined' is not a function (evaluating '$(document)')
我不知道是什么导致了它,甚至不知道它意味着什么.
I have no idea what is causing it or what it even means.
在萤火虫中,我明白了:
In firebug, I get this:
$ 不是函数
推荐答案
Wordpress 默认在 noConflict 模式下使用 jQuery.您需要使用 jQuery
作为变量名来引用它,而不是 $
,例如使用
Wordpress uses jQuery in noConflict mode by default. You need to reference it using jQuery
as the variable name, not $
, e.g. use
jQuery(document);
代替
$(document);
您可以轻松地将其封装在一个自执行函数中,以便 $
再次引用 jQuery(并避免污染全局命名空间),例如
You can easily wrap this up in a self executing function so that $
refers to jQuery again (and avoids polluting the global namespace as well), e.g.
(function ($) {
$(document);
}(jQuery));
这篇关于类型错误:'undefined' 不是函数(评估 '$(document)')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!