2014-07-15 112 views
3

我收到以下錯誤,它顯示爲Javascript沒有解釋$符號。Uncaught TypeError:undefined不是Wordpress中的函數(匿名函數)

未捕獲的類型錯誤:未定義不是函數main.js:1 (匿名功能)main.js:1

附在下面是main.js代碼。這回工作很好。我試圖找出在哪裏尋找問題的指針,即主題,jquery導入等。歡迎任何建議。

$(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(); 

}); 

回答

14

WordPress是在noConflict模式下默認運行時,DOM準備包裝改爲

jQuery(function($){ 

    // your code goes here 

}); 

否則$將不確定

Da Codex

+0

感謝您的建議。由於相同功能在2周前開始工作,所以我只能想一想,如果Wrodpress(3.9.1)的更新現在可能導致此問題被破壞。還有一種機制(例如更新主題)以使其像以前一樣工作(即不需要對代碼進行任何更改)。 – Mythbuster

+0

Sup,playaaaaaaaaaaaaaaaaaaa? –

相關問題