2012-03-04 80 views
0

我在這個論壇上搜索了答案,但一直未能找到答案。 這是我的問題:Jquery - Accordion - active state

我想禁用打開我的手風琴的第一和第二個窗格的可能性,並允許它只在需要時打開。這就像使一些窗格被禁用,一些啓用。

我已經搜查與此代碼:

$("#accordion").bind("accordionchangestart", function(event, ui) {     
    var active = $(this).accordion("option", "active"); 
     if(active == 0)||(active == 1)){ 
    preventDefault(); 
    }        
}); 

它僅適用於第二個窗格(== 1),因爲當國家是封閉的,它被認爲是假的,假== 0的jQuery 。

我試過搜索如果所選窗格是第一個與ui-state-active類,但是這太晚了,當類出現,窗格打開,這就是我想要阻止。

有什麼想法?

感謝

+0

你使用jQuery UI? – 2012-03-04 10:39:40

回答

0

如果您正在使用jQuery UI的手風琴不是你應該做的是使用changestart事件檢查被點擊其中一個,做任何你想做的事情。

使用此鍵來查看當前的狀態:

$("#accordion").accordion({changestart: function(event, ui) { 
     alert(ui.newHeader[0].textContent); 
}}); 

呦也可以改變當前選項是這樣的:

$("#accordion").accordion("activate", 3); 

你可以找到事件的文檔在這裏: http://jqueryui.com/demos/accordion/#events

而且這裏是激活方法文檔: http://jqueryui.com/demos/accordion/#method-activate

+0

謝謝,但這就是我在我的代碼中使用的。 問題是,我不能dertermine如果窗格點擊是第一個或不因爲false被認爲是0. – user1247956 2012-03-04 10:53:54

+0

@ user1247956我更正了我的答案。一探究竟。 – 2012-03-04 10:58:50

+0

謝謝,但我不知道如何使用ui.newHeader // jQuery對象,激活標題。你能幫我一點代碼嗎? – user1247956 2012-03-04 11:02:29

0

如果我只想採取行動擴大時:

var active = $(this.container).accordion('option', 'active'); 
if (!active && $.type(active) === 'boolean') { 
    //No action 
    return; 
} 
//Loading some data inside accordion content