jquery - 类型错误 : 'undefined' is not a function (evaluating '$(document)' )

标签 jquery wordpress

  1. 我正在使用 WordPress 网站。
  2. 我将此脚本包含在 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/

相关文章:

css - 字体无法在 Safari 或移动浏览器中呈现

php - 如何为谷歌字体指定缓存验证器

jquery - 当类低于特定索引时从 DIV 中删除类

javascript - 改变多个元素的样式

javascript - 单击创建一个 DIV;然后通过单击删除相同的 DIV

mysql - WordPress 插件查询中占位符的 PHPStorm 警告

wordpress - 递归加载其他组件的 React 组件

jquery - 响应式导航格式问题

javascript - 从父行获取 html 表数据

javascript - TypeError: jQuery ("#slider-full").revolution 不是函数