<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.hide{
display: none;
}
.menu{
height: 40px;
background-color: #eeeeee;
line-height: 40px;
}
.active{
background-color: brown;
}
.menu .item{
float: left;
padding: 0 15px;
border-right: 1px solid red;
cursor: pointer; /*鼠标变小手*/
}
.content{
height: 400px;
border: 1px solid black;
}
.text{
height: 400px;
}
</style>
</head>
<body>
<div style="width:700px; margin: 0 auto;">
<div class="menu">
<div class="item active" top="1">菜单一</div>
<div class="item" top="2">菜单二</div>
<div class="item" top="3">菜单三</div>
</div>
<div class="content">
<div class="text" bottom="1" style="background-color: red;">内容一</div>
<div class="text hide" bottom="2" style="background-color: blue;">内容二</div>
<div class="text hide" bottom="3" style="background-color: darkgreen;">内容三</div>
</div>
</div>
<script src="jquery-1.12.4.js"></script>
<script>
$(".item").click(function(){
$(this).addClass("active").siblings().removeClass("active");
var value = $(this).attr("top");
$(".content").children("[bottom='" + value + "']").removeClass("hide").siblings().addClass("hide");
});
</script>
</body>
</html>
jQuery TAB切换菜单示例
最新推荐文章于 2023-03-16 18:28:00 发布