Bootstrap Collapse的使用

1、效果图:
Bootstrap Collapse的使用_第1张图片
2、当点击B或C时,A自动收缩:
Bootstrap Collapse的使用_第2张图片Bootstrap Collapse的使用_第3张图片
3、html代码:

<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 class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
																A
															a>
														h4>
													div>
													<div id="collapseOne" class="panel-collapse  collapse in" role="tabpanel" aria-labelledby="headingOne">
														<ul class="list-group">
															<li class="list-group-item">1li>
															<li class="list-group-item">2li>
															<li class="list-group-item">3li>
														ul>
													div>
												div>

												<div class="panel panel-default">
													<div class="panel-heading" role="tab" id="headingTwo">
														<h4 class="panel-title">
															<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
																B
															a>
														h4>
													div>
													<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
														<ul class="list-group">
															<li class="list-group-item">1li>
															<li class="list-group-item">2li>
															<li class="list-group-item">3li>
														ul>
													div>
												div>

												<div class="panel panel-default">
													<div class="panel-heading" role="tab" id="headingThree">
														<h4 class="panel-title">
															<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
																C
															a>
														h4>
													div>
													<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
														<ul class="list-group">
															<li class="list-group-item">1li>
															<li class="list-group-item">2li>
															<li class="list-group-item">3li>
														ul>
													div>
												div>
											div>

其中最关键的是:data-parent=“#accordion”、aria-expanded=“true”、class=“panel-collapse collapse in”
(1)data-parent=“#accordion”:它指定的当前折叠框是在哪个下边,就是类似于分组,是指的在哪个分组下,该分组指定了ID(

(2)aria-expanded="true"表示默认展开,此属性需要配合class="panel-collapse collapse in"使用,否则会无法无法展开。
另需要注意:aria-controls、aria-labelledby的值。

你可能感兴趣的:(bootstrap,java,javascript)