2014-07-26 28 views
0

我的Js代碼有問題。在我的Webspace上它可以工作,但是在Wordpress系統上它不起作用。Js在Wordpress的錯誤,但不是一個不是WordPress的網站

下面是代碼:

$(document).ready(function(accordion){ 
    $('.item').click(function(accordion){ 
     if($(this).next('.item-data').css('display') != 'block'){ 
      $('.active').slideUp('slow').removeClass('active'); 
      $(this).next('.item-data').addClass('active').slideDown('slow'); 
     } else { 
      $('.active').slideUp('slow').removeClass('active'); 
     } 
    }); 
}); 

在我的私人網絡空間沒有任何錯誤,但在與WordPress網站空間: 未捕獲的SyntaxError:意外的標記功能

因此,它應該是這樣的:http://jsfiddle.net/Gamerfritz/5Wcqk/

+0

它是'jQuery(function($){code here});' – adeneo

+0

您確定此代碼有效嗎?看起來像有幾個丟失的圓括號給我。 – Owlvark

回答

0

在您發佈的示例代碼中,前兩個函數缺少左括號'('。您也可能想要更改$符號來表示jQuery,因爲這通常更適合於wordpress s ites(因爲他們可以使用$作爲別的標記)。在一個名爲accordion的函數中你也有一個名爲accordion的函數......我認爲這並不重要,因爲範圍的處理方式,但它看起來不是一個好主意。

也許嘗試這樣?

jQuery(document).ready(function accordion(){ 
jQuery('.item').click (function accordionClick() { 
    if(jQuery(this).next('.item-data').css('display') != 'block'){ 
     jQuery('.active').slideUp('slow').removeClass('active'); 
     jQuery(this).next('.item-data').addClass('active').slideDown('slow'); 
    } else { 
     jQuery('.active').slideUp('slow').removeClass('active'); 
    } 
}); 
}); 
相關問題