2012-12-03 72 views
0

我使用下面的腳本爲一個jQuery手風琴:收起jQuery的手風琴

(function($) { 

    var allPanels = $('.accordion > dd').hide(); 

    $('.accordion > dt > a').click(function() { 
    allPanels.slideUp(); 
    $(this).parent().next().slideDown(); 
    return false; 
    }); 

然而,當我點擊一個標題來關閉它,它關閉,然後imediately再次打開。腳本可以在這裏看到工作在這裏:http://www.one-event.org.uk/wordpress/#!/programme

所以我的問題是,我怎麼能使活動面板關閉,當我再次點擊它,而不是關閉和立即打開?

+0

大替代那些行,但問題是什麼? – Jai

回答

0

它立刻再次打開,因爲這是你的代碼是說做

allPanels.slideUp(); // Hide the panel 
$(this).parent().next().slideDown(); //Show it again 

allPanels.not(this).slideUp(); //hide only ones that aint this one. 
$(this).parent().next().slideToggle(); //show or hide based on current display