这应该让你开始:http: //jsfiddle.net/Xbg4n/45/
该示例不使用 .collapse,而仅使用 .slideUp 和 .slideDown... 应该很容易与折叠交换,但适用于示例目的。您真正从中得到的是目标,我认为这是您主要要问的。我还在其中添加了一些内容以循环回到第一个容器,但停在那里。您应该更好地控制焦点(避免关注锚标记并在循环回到第一个容器时强制焦点)。
您没有提供完整的 HTML 示例代码,所以我填写了空白:
<form id="myform">
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#createUserPanes" href="#collapseAcct">Account</a>
</div>
<div id="collapseAcct1" class="accordion-body collapse">
<div class="accordion-inner">
<div>
<input type="text" name="input1" />
<input type="text" name="input11" />
<input type="text" name="input12" />
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#createUserPanes" href="#collapseAcct">Settings</a>
</div>
<div id="collapseAcct3" class="accordion-body collapse">
<div class="accordion-inner">
<div>
<input type="text" name="input3" />
<input type="text" name="input31" />
<input type="text" name="input32" />
</div>
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#createUserPanes" href="#collapseAcct">Prefs</a>
</div>
<div id="collapseAcct2" class="accordion-body collapse">
<div class="accordion-inner">
<div>
<input type="text" name="input2" />
<input type="text" name="input21" />
<input type="text" name="input22" />
</div>
</div>
</div>
</div>
JS:
$('.accordion-group').each(function(){
var topcontainer = $(this);
topcontainer.find('input:last').each(function(){
$(this).blur(function(){
//swap slideup and slidedown for 'collapse' as appropriate
var nextag = topcontainer.next('.accordion-group');
var lastag = $('.accordion-group').last();
if(topcontainer.is(lastag)){
var nextag = $('.accordion-group').first();
}
var showag = nextag.find('.collapse');
var hideag = topcontainer.find('.collapse');
showag.slideDown();
hideag.slideUp();
});
});
});
CSS:
#collapseAcct2 {
display:none;
}
#collapseAcct3 {
display:none;
}