我使用jQuery,试图切换tab-pane
。目前,它仅适用于tab-pane
,但我也想从data-toggle="tab"
中删除活动的类。
$('[data-toggle=tab]').click(function() {
if ($(this).hasClass('active show')) {
$($(this).attr("href")).toggleClass('active show');
}
});
img {width: 48px}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab1">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h5></h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab2">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h5></h5>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#tab3">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h5></h5>
</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div id="tab1" class="container tab-pane"><br>
<div class="row">
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
</div>
</div>
<div id="tab2" class="container tab-pane fade"><br>
<div class="row">
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
</div>
</div>
<div id="tab3" class="container tab-pane fade"><br>
<div class="row">
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
<div class="col-md-4 case-tab-content">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/df/Imgur_icon.svg/240px-Imgur_icon.svg.png">
<h4>Sometext</h4>
</div>
</div>
</div>
</div>