我正在尝试使用 Bootstrap 3 使用可与 data 属性折叠的按钮来创建手风琴,而无需手风琴标记。它对我来说看起来更干净。
但是我无法使data-parent属性起作用。我想在打开一个问题时,关闭所有其他问题。我正在阅读文档(http://getbootstrap.com/javascript/#collapse-usage),但仍然无法使其正常工作。
我正在使用以下代码:
<div class="accordion" id="myAccordion">
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#collapsible-1" data-parent="#myAccordion">Question 1?</button>
<div id="collapsible-1" class="collapse">
<p>Etiam posuere quam ac quam. Maecenas aliquet accumsan leo. Nullam dapibus fermentum ipsum. Etiam quis quam. Integer lacinia. Nulla est.</p>
</div>
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#collapsible-2" data-parent="#myAccordion">Question 2?</button>
<div id="collapsible-2" class="collapse">
<p>Etiam posuere quam ac quam. Maecenas aliquet accumsan leo. Nullam dapibus fermentum ipsum. Etiam quis quam. Integer lacinia. Nulla est.</p>
</div>
<button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#collapsible-3" data-parent="#myAccordion">Question 3?</button>
<div id="collapsible-3" class="collapse">
<p>Etiam posuere quam ac quam. Maecenas aliquet accumsan leo. Nullam dapibus fermentum ipsum. Etiam quis quam. Integer lacinia. Nulla est.</p>
</div>
</div>
这是 JSFiddle:http: //jsfiddle.net/twinsen/AEew4/
如果有人指出我犯错的地方,我会很高兴:\