jQuery的tab切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 600px;
}
ul {
margin: 0px;
list-style: none;
padding: 0px;
height: 50px;
display: flex;
justify-content: space-around;
}
ul>li {
padding: 12px 9px;
width: 100px;
text-align: center;
cursor: pointer;
}
ul>li:hover {
color: blue;
}
.show {
border-bottom: 2px solid red;
color: blue;
}
#div>div {
height: 400px;
border: 1px solid black;
display: none;
}
</style>
</head>
<body>
<div class="box">
<ul id="ul">
<li class="show">商品名称</li>
<li>详情列表</li>
<li>售后咨询</li>
</ul>
<div id="div">
<div style="display:block;">1</div>
<div>2</div>
<div>3</div>
</div>
</div>
<!-- <script src="./jquery-2.1.4.min.js"></script> -->
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#ul").children("li").each(function (index, element) {
$(this).click(function () {
$(this).addClass('show').siblings().removeClass('show')
$($("#div").children()[index]).css("display", "block")
$($("#div").children()[index]).siblings().css("display", "none")
})
})
})
</script>
</body>
</html>