wordpress 报错 TypeError: $ is not a function

发布时间: 2017-03-25 16:11:59 作者: 大象笔记

代码非常简单,第一行就报错了

$(document).ready(function() {
    // Code 
});

TypeError: $ is not a function

估计是 $ 冲突了,果然,修改成下面的代码即可

jQuery(document).ready(function($) { // Code });

This is because WordPress may use $ for something other than jQuery, in the future, or now, and so you need to load jQuery in a way that the $ can be used only in a jQuery document ready callback.

这样写的确是良好的习惯,即使不在 wordpress 项目中也应该这样写。

我是一名山东烟台的开发者,联系作者