<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"><div class="panel-body">关闭
标签,并开始 OPEN.第二个面板切换这些,然后开始关闭.
编辑
无法制作 Bootply,不断收到应用程序错误".
I'm using Bootstrap Accordion. I want all the panel closed by default, but my panels are start expanded.
Here's my code:
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="false">
<c:forEach items="${proposals}" var="proposal" varStatus="serial">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading${proposal.propID}" >
<h4 class="panel-title">
<span class="fa fa-paperclip" aria-hidden="true"></span>
<a class="accordion-toggle collapsed"
data-toggle="collapse" data-parent="#accordion"
href="#collapse${proposal.propID}" aria-expanded="false"
aria-controls="collapse${proposal.propID}">
${proposal.title}
</a>
</h4>
</div>
<div id="collapse${proposal.propID}" class="panel-collapse collapse in"
role="tabpanel" aria-labelledby="heading${proposal.propID}">
${proposal.interest}
</div>
</div>
</c:forEach>
</div>
I also used aria-expanded="false"
, but it doesn't work.
What's the mistake?
解决方案
This line here seems to be the culprit:
<div id="collapse${proposal.propID}" class="panel-collapse collapse in" ...
If you get rid of in
in the class, it should work as you have it structured. Take a look at this example to see the difference between the two panels:
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
This Panel is Open By Default
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
Open
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
This Panel Is Closed By Default
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
Closed
</div>
</div>
</div>
</div>
Notice the first panel doesn't have the class=collapsed
on it's <a>
tag, and has the in
class on it's <div>
tag, and starts OPEN. The second panel switches those, and starts CLOSED.
EDIT
Can't make a Bootply, keep getting "Application Error".
这篇关于在 Bootstrap 中默认关闭手风琴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!