2013-03-05 17 views
0

我在演示中使用了一個基本的jQuery Accordion。我點擊「關於我們」,它會顯示下方的「團隊」鏈接。好極了!對jQuery Accordion稍作調整

現在,是否有可能讓這個手風琴上班沒有必須在超鏈接中有'item'類?

因此,而不是<a href="/about-us/" class="item">About Us</a>它只是<a href="/about-us/">About Us</a>?我問的原因是目前從WordPress生成的代碼不包括'item'類,因此打破了我的手風琴。

這裏是我的演示http://jsfiddle.net/h32dj/

而且我的JavaScript:

jQuery(function($) { 

    $('#accordion a.item').click(function (e) { 
    //remove all the "Over" class, so that the arrow reset to default 
    $('#accordion a.item').not(this).each(function() { 
    if ($(this).attr('rel')!='') { 
    $(this).removeClass($(this).attr('rel') + 'Over'); 
    } 
    $(this).siblings('ul').slideUp("slow"); 
    }); 

    //showhide the selected submenu 
    $(this).siblings('ul').slideToggle("slow"); 

    //addremove Over class, so that the arrow pointing downup 
    $(this).toggleClass($(this).attr('rel') + 'Over'); 
    e.preventDefault(); 
    }); 

}); 

這裏任何指針:)感謝

回答

1

那麼,讓我們來分析一下item類是如何使用這個腳本。據我所知,需要以某種方式區分第一級錨(手風琴窗格)和第二級錨(內容)。如果您需要刪除此課程,那麼您需要其他方法。例如,您可以依賴標記和標記層次結構。具體而言,而不是由類選擇的:

'#accordion a.item' 

使用選擇按層次結構:

'#accordion > li > a' 

這裏是demo

+0

演示精美的作品!謝謝!!!現在我要嘗試並融入我的解決方案。回到2分鐘:) – michaelmcgurk 2013-03-05 11:11:58

+0

這很好用 - 很多,非常感謝您的詳細回覆和解決方案。祝你有美好的一天!!! – michaelmcgurk 2013-03-05 11:13:23

+0

Hi @Andrei。我現在注意到的只有輕微的問題是,當我點擊「新聞」時,它不會導航到任何地方。有沒有解決的辦法? – michaelmcgurk 2013-03-05 11:38:31

0

沒有項目類,它會沿着線工作:

jQuery(function($) { 

    $('#accordion > li > a').click(function (e) { 
    //remove all the "Over" class, so that the arrow reset to default 
     $('#accordion a').not(this).each(function() { 
      if ($(this).attr('rel')!='') { 
       $(this).removeClass($(this).attr('rel') + 'Over'); 
      } 
     $(this).siblings('ul').slideUp("slow"); 
    }); 

    //showhide the selected submenu 
    $(this).siblings('ul').slideToggle("slow"); 

    //addremove Over class, so that the arrow pointing downup 
    $(this).toggleClass($(this).attr('rel') + 'Over'); 
     e.preventDefault(); 
    }); 

}); 

Link to jsfiddle

+0

嗨,馬蒂。那很完美。安德烈在你面前發表了一分鐘左右的回答。非常感謝把這個答案放在一起,這有助於我更多地理解它:) – michaelmcgurk 2013-03-05 11:14:12