<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
#box{
margin-left: 100px;
margin-top: 100px;
}
ul{
list-style: none;
width: 280px;
height: 32px;
}
.lie>li{
float: left;
border: 1px solid gainsboro;
height: 32px;
width:70px;
box-sizing: border-box;
border-left: none;
text-align: center;
line-height: 32px;
cursor: pointer;
}
.lie-list li{
width: 280px;
height: 200px;
border: 1px solid gainsboro;
box-sizing: border-box;
border-top: none;
display: none;
}
.lie>li a{
text-decoration: none;
font-family: "楷体";
font-size: 24px;
color:gray;
}
.active{
background: deepskyblue;
}
/* 元素第一个子元素 css3*/
.lie-list>li:nth-child(1){
display: block;
}
</style>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$(".lie").on("click","li",function(){
var index = $(this).index()
$(this).parent().siblings().children("li:eq(" + $(this).index() + ")").show().siblings().hide();
$(this).addClass("active").siblings().removeClass("active");
});
})
</script>
</head>
<body>
<div id="box">
<ul class="lie">
<li class="active">电影</li>
<li>娱乐</li>
<li>生活</li>
<li>军事</li>
</ul>
<ul class="lie-list">
<li>电影......</li>
<li>娱乐......</li>
<li>生活......</li>
<li>军事......</li>
</ul>
</div>
</body>
</html>
jQuery实现选项卡
最新推荐文章于 2022-11-14 15:31:33 发布