当用户点击菜单标签时,我需要打开相应的标签内容,再次点击菜单标签后内容将关闭。
我已从标签菜单和标签内容中删除了所有活动类。
$(document).on('click','.nav-link.active', function(){
var href = $(this).attr('href').substring(1);
$(this).removeClass('active');
$('.tab-pane[id="'+ href +'"]').toggleclass('active');
});
<!-- Nav tabs -->
<ul class="nav" role="tablist">
<li class="nav-item">
<a class="nav-link " data-toggle="tab" href="#home" role="tab">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#profile" role="tab">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#messages" role="tab">Messages</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#settings" role="tab">Settings</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane" id="home" role="tabpanel">ZOOO</div>
<div class="tab-pane" id="profile" role="tabpanel">ABC</div>
<div class="tab-pane" id="messages" role="tabpanel">123</div>
<div class="tab-pane" id="settings" role="tabpanel">EFG</div>
</div>
这是小提琴Example