你所描述的你想要的在 Twitter.Bootstrap 中被称为“折叠”或“手风琴” 。请参阅将此与您的解决方案进行比较的jsFiddle。手风琴的代码:
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">
Show Foo Bar
</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">Foo Bar</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">Show Herp Derp</a>
</div>
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">Herp Derp</div>
</div>
</div>
</div>
要在一行中使用两个按钮:
<div class="accordion" id="accordion2">
<div class="accordion-group">
<div >
<a class="accordion-toggle btn" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne"> Show Foo Bar</a>
<a class="accordion-toggle btn" data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo">Show Herp Derp</a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">Foo Bar</div>
</div>
</div>
<div class="accordion-group">
<div id="collapseTwo" class="accordion-body collapse">
<div class="accordion-inner">Herp Derp</div>
</div>
</div>
</div>