如何一次打开一个手风琴选项卡 引导程序.



我在尝试获取它时遇到麻烦,所以我的 Bootstrap 手风琴样式表单一次只能打开一个步骤选项卡。我需要更改什么才能一次只打开一个选项卡?

这是指向完整内容的CodePen链接。 这是我的HTML的一部分:

<div id="accordion" role="tablist" aria-multiselectable="false">
<div class="card">
<div class="card-header" role="tab" id="headingOne">
<div class="mb-0">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne" class="collapsed">
<h3>Step 1 of 4: Create Profile</h3>
<div class="edit-step">Edit Step</div>
</a>
</div>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne" aria-expanded="false" style="">
<div class="card-block">
<form>
<h1>Organization</h1>
<label>Membership Category</label>
<select id="category">
<option value=""></option>
<option value="CM">Company</option>
<option value="NS">Educational</option>
<option value="GM">Government</option>
<option value="OM">Organizational</option>
<option value="IND">Individual</option>
<option value="RET">Retail</option>
</select><br><br>
<div id="continue1" class="continue-button">Continue</div><br>
</form>
</div>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<div class="mb-0">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseOne" class="collapsed">
<h3>Step 2 of 4: Payment Information</h3>
<div class="edit-step">Edit Step</div>
</a>
</div>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo" aria-expanded="false">
<div class="card-block">
<form>
<h1>Organization</h1>
<br><br>
<div id="continue2" class="continue-button">Continue</div><br>
</form>
</div>
</div>
</div>

由于您已经在项目中使用 jQuery,因此您只需选择具有类panel-collapse collapse in的所有div 并删除该类in

Codepen: https://codepen.io/anon/pen/yxMyqY

$(document).ready(function(){
$("[data-parent='#accordion']").on("click", function(){
var trigger = $(this);
$(".panel-collapse.collapse.in").each(function(){
if( trigger.attr("href") != ("#"+$(this).attr("id")) ){
$(this).removeClass("in");
} // condition returns false on iteration on div to be opened
});   
});
});

相关内容

  • 没有找到相关文章

最新更新