TypeError:“未定义"不是函数(评估“$(文档)") [英] TypeError: 'undefined' is not a function (evaluating '$(document)')
问题描述
- 我使用的是 WordPress 网站.
- 我将这个脚本包含在标题中.
当脚本加载时,我得到这个错误:
When the script loads, I get this error:
TypeError: 'undefined' is not a function (evalating '$(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));
这篇关于TypeError:“未定义"不是函数(评估“$(文档)")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!