<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>选项卡</title>
<link rel="stylesheet" href="assets/css/amazeui.min.css">
<!--[if (gte IE 9)|!(IE)]><!-->
<script src="assets/js/jquery.min.js"></script>
<!--<![endif]-->
<!--[if lte IE 8 ]>
<script src="assets/ie8/jquery.min.js"></script>
<script src="assets/ie8/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<script src="assets/js/amazeui.min.js"></script>
</head>
<body style="margin: 50px;">
<style>
.am-tabs-nav li {
position: relative;
z-index: 1;
}
.am-tabs-nav .am-icon-close {
position: absolute;
top: 0;
right: 10px;
color: #888;
cursor: pointer;
z-index: 100;
}
.am-tabs-nav .am-icon-close:hover {
color: #333;
}
.am-tabs-nav .am-icon-close ~ a {
padding-right: 25px!important;
}
</style>
<!--内容高度一致-->
<div class="am-tabs" data-am-tabs="{noSwipe: 1}" id="doc-tab-demo-1">
<ul class="am-tabs-nav am-nav am-nav-tabs">
<li class="am-active"><a href="javascript: void(0)">列表一</a></li>
<li><a href="javascript: void(0)">列表二</a></li>
<li><a href="javascript: void(0)">列表三</a></li>
</ul>
<div class="am-tabs-bd">
<div class="am-tab-panel am-active">内容1</div>
<div class="am-tab-panel">内容2</div>
<div class="am-tab-panel">内容3</div>
</div>
</div>
<br />
<button type="button" class="am-btn am-btn-primary js-append-tab">插入 Tab</button>
<script>
$(function() {
var tabCounter = 0;
var $tab = $('#doc-tab-demo-1');
var $nav = $tab.find('.am-tabs-nav');
var $bd = $tab.find('.am-tabs-bd');
function addTab() {
var nav = '<li><span class="am-icon-close"></span>' +
'<a href="javascript: void(0)">标签 ' + tabCounter + '</a></li>';
var content = '<div class="am-tab-panel">动态插入的标签内容' + tabCounter + '</div>';
$nav.append(nav);
$bd.append(content);
tabCounter++;
$tab.tabs('refresh');
}
// 动态添加标签页
$('.js-append-tab').on('click', function() {
addTab();
});
// 移除标签页
$nav.on('click', '.am-icon-close', function() {
var $item = $(this).closest('li');
var index = $nav.children('li').index($item);
$item.remove();
$bd.find('.am-tab-panel').eq(index).remove();
$tab.tabs('open', index > 0 ? index - 1 : index + 1);
$tab.tabs('refresh');
});
});
</script>
</body>
</html>
效果图:
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>选项卡</title>
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp"/>
<link rel="icon" type="image/png" href="assets/i/favicon.png">
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="192x192" href="assets/i/app-icon72x72@2x.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Amaze UI"/>
<link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
<meta name="msapplication-TileImage" content="assets/i/app-icon72x72@2x.png">
<meta name="msapplication-TileColor" content="#0e90d2">
<link rel="stylesheet" href="assets/css/amazeui.min.css">
</head>
<body style="margin: 50px;">
<!--允许触控操作-->
<div class="am-tabs" data-am-tabs>
<ul class="am-tabs-nav am-nav am-nav-tabs">
<li class="am-active"><a href="#tab1">列表1</a></li>
<li><a href="#tab2">列表2</a></li>
<li><a href="#tab3">列表3</a></li>
</ul>
<div class="am-tabs-bd">
<div class="am-tab-panel am-fade am-in am-active" id="tab1">
内容1<br>内容1
</div>
<div class="am-tab-panel am-fade" id="tab2">
内容2
</div>
<div class="am-tab-panel am-fade" id="tab3">
内容3
</div>
</div>
</div>
<br>
<!--禁用触控操作-->
<div class="am-tabs" data-am-tabs="{noSwipe: 1}">
<ul class="am-tabs-nav am-nav am-nav-tabs">
<li class="am-active"><a href="#tab2-1">列表1</a></li>
<li><a href="#tab2-2">列表2</a></li>
<li><a href="#tab2-3">列表3</a></li>
</ul>
<div class="am-tabs-bd">
<div class="am-tab-panel am-fade am-in am-active" id="tab2-1">
内容1<br>内容1
</div>
<div class="am-tab-panel am-fade am-in" id="tab2-2">
内容2<br>内容2
</div>
<div class="am-tab-panel am-fade am-in" id="tab2-3">
内容3<br>内容3<br>内容3
</div>
</div>
</div>
<!--[if (gte IE 9)|!(IE)]><!-->
<script src="assets/js/jquery.min.js"></script>
<!--<![endif]-->
<!--[if lte IE 8 ]>
<script src="assets/ie8/jquery.min.js"></script>
<script src="assets/ie8/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<script src="assets/js/amazeui.min.js"></script>
</body>
</html>
效果图: