<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<style>
.tabcon{display: none}
.tabcon.active{
display: block;
}
.tabitem.active{color: red;}
</style>
<body>
<ul>
<li class="tabitem active"><a href="#">页面一</a></li>
<li class="tabitem"><a href="#">页面二</a></li>
<li class="tabitem"><a href="#">页面三</a></li>
</ul>
<div class="tabcon active">内容一</div>
<div class="tabcon">内容二</div>
<div class="tabcon">内容三</div>
</body>
<script src="jquery-3.0.0.js"></script>
<script>
$(".tabitem").click(function(){
var lis=$(".tabitem")
var divs=$(".tabcon")
for(var i=0;i<lis.length;i++){
if(lis[i]==this){
$('.tabitem').removeClass('active')
$('.tabcon').removeClass('active')
lis.eq(i).addClass("active")
divs.eq(i).addClass("active")
}
}
})
</script>
</html>
转载于:https://www.cnblogs.com/vonson/p/7610276.html