tab选项卡--jq

时间:2021-05-27 12:24:32
 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>tab</title>
<script src="jquery.min.js"></script>
<style>
.active{
background: yellow;
}
#contents div{
width: 200px;
height: 200px;
background: #ccc;
border: 1px solid #999;
display: none;
}
</style>
</head>
<body>
<input type="button" value="教育" class="active" />
<input type="button" value="培训" />
<input type="button" value="招生" />
<input type="button" value="出国" />
<div id="contents">
<div style="display: block;">1111</div>
<div>2222</div>
<div>3333</div>
<div>4444</div>
</div>
<script>
$('input').click(function(){
$(this).addClass('active').siblings().removeClass('active'); $('#contents>div').eq($(this).index()).show().siblings().hide();
});
</script>
</body>
</html>