選項卡的實現是通過JQuery實現的,通過引進JS庫,然後通過模塊的點擊事件,實現頁面切換。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>選項卡</title>
<style>
.tab_con{
width:500px;
height:350px;
margin:50px auto 0;
}
.tab_btns{
height:50px;
}
.tab_btns input{
width:100px;
height:50px;
background:#ddd;
border:0px;
outline:none;
}
.tab_btns .active{
background:gold;
}
.tab_cons{
height:300px;
background:gold;
}
.tab_cons div{
height:300px;
line-height:300px;
text-align:center;
display:none;
font-size:30px;
}
.tab_cons .current{
display:block;
}
</style>
<script src="js/jquery-1.12.4.min.js"></script>
<script>
//ready函數
$(function (){
//獲取模塊
var $btn = $('.tab_btns input ');
var $div = $('.tab_cons div');
//設置點擊事件
$btn.click(function(){
//添加點擊模塊的樣式類,刪除其餘模塊的樣式類。
$(this).addClass('active').siblings().removeClass('active');
//根據按鈕的索引增加DIV模塊的樣式類,刪除其餘模塊的樣式類。
$div.eq($(this).index()).addClass('current').siblings().removeClass('current');
})
})
</script>
</head>
<body>
<div class="tab_con">
<div class="tab_btns">
<input type="button" value="按鈕一" class="active">
<input type="button" value="按鈕二">
<input type="button" value="按鈕三">
</div>
<div class="tab_cons">
<div class="current">按鈕一對應的內容</div>
<div>按鈕二對應的內容</div>
<div>按鈕三對應的內容</div>
</div>
</div>
</body>
</html>