- 我正在使用 WordPress 网站。
- 我将此脚本包含在 header 中。
当脚本加载时,我得到这个错误:
TypeError: 'undefined' is not a function (evaluating '$(document)')
我不知道是什么原因造成的,甚至不知道它意味着什么。
在 Firebug 中,我得到这个:
$ is not a function
最佳答案
WordPress 在 noConflict 中使用 jQuery默认模式。您需要使用 jQuery
作为变量名来引用它,而不是 $
,例如使用
jQuery(document);
代替
$(document);
您可以轻松地将它包装在一个自执行函数中,以便 $
再次引用 jQuery(并避免污染全局命名空间),例如
(function ($) {
$(document);
}(jQuery));
关于jquery - 类型错误 : 'undefined' is not a function (evaluating '$(document)' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7975093/