Bootstrap手风琴无法正常工作。如果我单击一个手风琴选项卡,则它关闭了另一个手风琴,有时又关闭并再次打开。第一次它可以正常工作,但是下一次它不能正常工作如果我单击一个选项卡,它将关闭另一个选项卡,否则它将在关闭后默认打开。
<div class="col-lg-6">
<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 role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Notify Users
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<form>
<div class="row">
<div class="form-group">
<div class="col-lg-6">
<select id="selection" class="form-control">
<option>All Users</option>
<option>Metronomic</option>
<option>Fairfax Users</option>
</select>
</div>
<div class="col-lg-6">
<select id="selection" class="form-control">
<option>App Notify</option>
<option>Email</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" placeholder="Notification title here..." id="title">
</div>
<div class="form-group">
<label for="last">Sub Title</label>
<input type="text" class="form-control" placeholder="Notification sub title here..." id="sub-title">
</div>
<div class="form-group">
<label for="notificationcontent">Notification Content</label>
<textarea class="form-control" placeholder="" id="notificationcontent"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Notification</button>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
Notify Users
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form>
<div class="row">
<div class="form-group">
<div class="col-lg-6">
<select id="selection" class="form-control">
<option>All Users</option>
<option>Metronomic</option>
<option>Fairfax Users</option>
</select>
</div>
<div class="col-lg-6">
<select id="selection" class="form-control">
<option>App Notify</option>
<option>Email</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" placeholder="Notification title here..." id="title">
</div>
<div class="form-group">
<label for="last">Sub Title</label>
<input type="text" class="form-control" placeholder="Notification sub title here..." id="sub-title">
</div>
<div class="form-group">
<label for="notificationcontent">Notification Content</label>
<textarea class="form-control" placeholder="" id="notificationcontent"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Notification</button>
</form>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
您错误地分配了data-parent="#accordion"
,您必须为此分配Collapse div并使用单亲<div id="accordion"></div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="col-lg-6">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="row">
<div class="panel panel-default col-md-6">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Notify Users
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne" data-parent="#accordion">
<div class="panel-body">
<form>
<div class="row">
<div class="form-group">
<div class="col-lg-12">
<select id="selection" class="form-control">
<option>All Users</option>
<option>Metronomic</option>
<option>Fairfax Users</option>
</select>
</div>
<div class="col-lg-12">
<select id="selection" class="form-control">
<option>App Notify</option>
<option>Email</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" placeholder="Notification title here..." id="title">
</div>
<div class="form-group">
<label for="last">Sub Title</label>
<input type="text" class="form-control" placeholder="Notification sub title here..." id="sub-title">
</div>
<div class="form-group">
<label for="notificationcontent">Notification Content</label>
<textarea class="form-control" placeholder="" id="notificationcontent"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Notification</button>
</form>
</div>
</div>
</div>
<div class="panel panel-default col-md-6">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" href="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
Notify Users
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="panel-body">
<form>
<div class="row">
<div class="form-group">
<div class="col-lg-12">
<select id="selection" class="form-control">
<option>All Users</option>
<option>Metronomic</option>
<option>Fairfax Users</option>
</select>
</div>
<div class="col-lg-12">
<select id="selection" class="form-control">
<option>App Notify</option>
<option>Email</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" placeholder="Notification title here..." id="title">
</div>
<div class="form-group">
<label for="last">Sub Title</label>
<input type="text" class="form-control" placeholder="Notification sub title here..." id="sub-title">
</div>
<div class="form-group">
<label for="notificationcontent">Notification Content</label>
<textarea class="form-control" placeholder="" id="notificationcontent"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Notification</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>