这篇文章给大家分享的是有关bootstrap实现tab选项卡切换的方法是什么的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
在项目中遇到要实现tab选项卡的关闭功能,项目中用的bootstrap框架,网上有很多插件,我这里只是简单的实现了tab选项卡的切换! <
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.min.css" rel="external nofollow" >
<title>产品制作</title>
</head>
<body>
<!--内容部分-->
<div class="qb-content-wrapper">
<div class="qb-content">
<!--当前位置-->
<div class="currentLocation clearfix">
<span class="pull-left">产品管理 > 产品制作</span>
<div class="nav-btn pull-right">
<input type="button" class="btn btn-info" value="桌面">
<input type="button" class="btn btn-info returnBtn" value="返回">
</div>
</div>
<!--主要内容-->
<div class="container-fluid">
<div class="row qb-content-wrapper qb-main-content">
<div class="col-md-12 col-xs-12">
<ul class="nav nav-tabs tabs" role="tablist">
<li role="presentation" class="tab-list active">
<a href="#home" rel="external nofollow" aria-controls="home" role="tab" data-toggle="tab">信息检索
<i class="fa fa-remove tab-close"></i></a>
</li>
<li role="presentation" class="tab-list"><a href="#profile" rel="external nofollow" rel="external nofollow" aria-controls="profile" role="tab" data-toggle="tab">产品制作
<i class="fa fa-remove tab-close"></i></a>
</li>
<li role="presentation" class="tab-list">
<a href="#home1" rel="external nofollow" aria-controls="home" role="tab" data-toggle="tab">信息检索1
<i class="fa fa-remove tab-close"></i></a>
</li>
<li role="presentation" class="tab-list"><a href="#profile" rel="external nofollow" rel="external nofollow" aria-controls="profile1" role="tab" data-toggle="tab">产品制作1
<i class="fa fa-remove tab-close"></i></a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">
信息检索
</div>
<div role="tabpanel" class="tab-pane" id="profile">
产品制作
</div>
<div role="tabpanel" class="tab-pane" id="home1">
信息检索
</div>
<div role="tabpanel" class="tab-pane" id="profile1">
产品制作
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script></script>
<script src="js/jquery-1.11.2-min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$('.tab-close').on('click', function(ev) {
var ev=window.event||ev;
ev.stopPropagation();
//先判断当前要关闭的tab选项卡有没有active类,再判断当前选项卡是否最后一个,如果是则给前一个选项卡以及内容添加active,否则给下一个添加active类
var gParent=$(this).parent().parent(),
parent=$(this).parent();
if(gParent.hasClass('active')){
if(gParent.index()==gParent.length){
gParent.prev().addClass('active');
$(parent.attr('href')).prev().addClass('active');
}else{
gParent.next().addClass('active');
$(parent.attr('href')).next().addClass('active');
}
}
gParent.remove();
$(parent.attr('href')).remove();
});
</script>
</body>
</html>
感谢各位的阅读!关于bootstrap实现tab选项卡切换的方法是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。