未捕获的TypeError:未定义不是Wordpress中的函数(匿名函数)
问题描述:
我遇到以下错误,这似乎是Javascript无法解释$符号.
I am getting the following error, which appears to be Javascript not interpreting the $ symbol.
未捕获的TypeError:undefined不是函数main.js:1 (匿名函数)main.js:1
Uncaught TypeError: undefined is not a function main.js:1 (anonymous function) main.js:1
下面附加的是main.js代码.回来的时候这个工作很好.我正在尝试找出指向哪里寻找问题的指针,即主题,jQuery导入等.欢迎提出任何建议.
Appended below is the main.js code. This was working fine sometime back. I am trying to find out pointers to where to look for the issues, i.e. theme, jquery imports, etc. Any suggestions are welcome.
$(function(){
var cardHeight = 0;
function _setCardHeight(){
$(".subpage-box").each( function(){ var current_height =
$(this).height();
cardHeight = ( current_height > cardHeight) ? current_height :
cardHeight;
}); $(".subpage-box").each( function(){ if( $(this).height() <
cardHeight ){ $(this).height( cardHeight ); } });
}
function _setNavStyle(){
$("menu-main-menu > li > a").each( function(){
var text = $(this).html();
if( $(this).contains("for") ){
}
});
}
_setNavStyle();
_setCardHeight();
});
答
默认情况下,WordPress在noConflict模式下运行,将DOM ready wrap更改为
Wordpress is running in noConflict mode by default, change the DOM ready wrapping to
jQuery(function($){
// your code goes here
});
否则$将是不确定的