jquery accordion:在其他面板上打开指定的面板

时间:2013-11-23 06:12:48

标签: jquery panel accordion

我是JQuery和javascript的新手,可以真正使用一些帮助。

我想组装一个有8个面板的手风琴,默认面板是#8。它在页面加载时打开。默认情况下,当我打开任何其他面板时#8将关闭,并且除非我专门打开它,否则它将保持关闭状态,无论我打开或关闭哪个面板。

我需要知道的是:每次关闭打开的面板时是否可以自动打开#8。

例如,我打开面板3,它关闭所有当前打开的面板。当我关闭面板3时,我希望面板8自动打开。

这可能吗?

谢谢

1 个答案:

答案 0 :(得分:1)

是的,这是可能的。以下是使用jQuery UI的示例:

$(function() {
    var activePanel = 2; //Set to the zero-based index of the panel you want to open
    $( "#accordion" ).accordion({
        collapsible: true,
        active: activePanel,
        activate: function(event,ui){
            //If a panel other than our default is collapsed
            if(!ui.newPanel.length && $(this).find('.ui-accordion-content').index(ui.oldPanel) != activePanel){
                $(this).accordion('option','active',activePanel);
            }
        }
    });
  });

<强> Demo fiddle