tab切换 (选项卡)----有详细注释
.tab-btn-box {
display:flex;
justify-content: space-between;
width:600px;
}
.tab-btn-box .tab-btn {
width: 100px;
height:40px;
background:#ccc;
line-height:40px;
border:1px solid #000;
text-align: center;
cursor: pointer;
}
.tab-box .tab-small-box{
width:600px;
height:300px;
margin-top:10px;
background:#ccc;
}
.active{
background:pink !important;
}
.tabBox-hide{
display:none;
}
.tabBox-show{
display:block;
}
<!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">
<link rel="stylesheet" href="css/tab.css">
<title>tab切换</title>
</head>
<body>
<div class="tab-btn-box">
<div class="tab-btn active">按钮1</div>
<div class="tab-btn">按钮2</div>
<div class="tab-btn">按钮3</div>
<div class="tab-btn">按钮4</div>
<div class="tab-btn">按钮5</div>
</div>
<div class="tab-box">
<div class="tab-small-box">页面1111111111111111111111111111</div>
<div class="tab-small-box tabBox-hide">页面2222222222222222222222222222</div>
<div class="tab-small-box tabBox-hide">页面3333333333333333333333333333</div>
<div class="tab-small-box tabBox-hide">页面4444444444444444444444444444</div>
<div class="tab-small-box tabBox-hide">页面5555555555555555555555555555</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$(document).ready(function () {
$(".tab-btn").click(function () {
$(this).addClass("active").siblings().removeClass("active")
var btnIndex = $(this).index();
var boxIndex = $(".tab-small-box").eq(btnIndex);
boxIndex.addClass("tabBox-show").removeClass("tabBox-hide").siblings().removeClass("tabBox-show").addClass("tabBox-hide")
});
});
</script>
</body>
</html>