2013-03-17 50 views
0

我爲我的側邊欄導航使用了jQuery Accordion。目前我有兩個鏈接,其中都有「孩子」。jQuery Accordion的基本問題

這裏是我的jsfiddle:http://jsfiddle.net/6Eh8C/

你會發現,當你點擊「關於我們」,畫廊關閉。這不應該發生。只有點擊「圖庫」後,圖庫才應該關閉。

我該如何解決這個問題?

這裏是我的jQuery:

jQuery(function($) { 

     $('#accordion > li > a').click(function (e) { 
      if ($(this).next('ul').length == 0) { 
       // link is for navigation, do not set up accordion here 
       return; 
      } 

      // link is for accordion pane 

      //remove all the "Over" class, so that the arrow reset to default 
      $('#accordion > li > 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(); 
     });  

     $('.slides_item').children('div').css('background','#ededed') 

    }); 

爲:-)

回答

0

任何指針非常感謝我覺得你只是想刪除一個行:

$('#accordion > li > a').not(this).each(function() { 
    if ($(this).attr('rel')!='') { 
     $(this).removeClass($(this).attr('rel') + 'Over'); 
    } 

    // Remove this line, you don't want to slide up other uls. 
    // $(this).siblings('ul').slideUp("slow"); 
}); 

例子:http://jsfiddle.net/6Eh8C/1/

+0

哇。我真的應該看到這一點。非常感謝如此快速的回覆。 – michaelmcgurk 2013-03-17 18:55:33

+0

完美無缺 - 非常感謝。將在5分鐘內接受答案:) – michaelmcgurk 2013-03-17 18:56:51

+1

@michaelmcgurk:沒問題!樂意效勞。 – 2013-03-17 18:57:27