bootstrap实现选项卡切换
时间: 2023-07-18 19:42:48 浏览: 152
bootstrap实现tab选项卡切换
要使用Bootstrap实现选项卡切换,需要使用以下HTML和JavaScript代码:
HTML代码:
```
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">Home content</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">Profile content</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">Contact content</div>
</div>
```
JavaScript代码:
```
$('#myTab a').on('click', function (e) {
e.preventDefault()
$(this).tab('show')
})
```
这段代码会将选项卡与相应的内容绑定起来,并在切换选项卡时显示相应的内容。
阅读全文