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