2011-05-26 96 views
0

打開手風琴項目然後點擊新的手風琴項目後,我希望它先關閉打開的手風琴項目,然後打開新手風琴項目。如何在打開下一個之前關閉jQuery手風琴?

這裏是我當前的代碼:

jQuery('.acclink').click(function() { 
    jQuery("#accordion").accordion("activate", -1); // this closes anything open 
    jQuery(jQuery(this).attr('href')).click(); // this is supposed to open the new one but doesn't. It WILL work when the above function is commented out. 
    return false; 
}); 

這裏是我的網頁:http://www.savedeth.com/objectivescenes/ 我缺少什麼?

+1

不手風琴在默認情況下做到這一點? – 2011-05-26 18:09:50

+0

不完全。它會從上面或下面滑動新的。我希望它完全關閉,然後打開一個新的。 – Dave 2011-05-26 18:13:07

+0

這只是與動畫的速度有關嗎? – 2011-05-27 12:32:14

回答

0

無需鍵入jQuery,$('#accordion').<method>就足夠了。

您確定jQuery(jQuery(this).attr('href'))正在選擇您想要的嗎? 打印使用console.log(Query(jQuery(this).attr('href')))

我認爲手風琴已經做好了你自己需要的一切。

可能$('#accordion').accordion()是最簡單的解決方案。

+0

下面是示例頁面:http://www.savedeth.com/objectivescenes/(點擊「部分」鏈接) – Dave 2011-05-26 18:15:22

0

查看jqueryui.com上的鏈接,手風琴默認是這樣做的。 http://jqueryui.com/demos/accordion/

+0

...不完全。檢查我的示例頁面。它應該完全關閉手風琴,然後再打開。 – Dave 2011-05-26 18:27:04

1

試試這個

$(document).ready(function() { ("#accordion").accordion;}); 
相關問題