选项卡功能
作者:
凌Linny | 来源:发表于
2017-03-08 22:37 被阅读0次<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#div1 .active {
background:yellow;
}
#div1 div {
width: 200px;
height: 200px;
background-color: #ccc;
border:1px solid #999;
display: none;
}
</style>
</head>
<body>
<div id="div1">
<input class="active" type="button" value="教育">
<input type="button" value="培训">
<input type="button" value="招生">
<input type="button" value="出国">
<div style="display:block">今天吃了几盆饭,真是饭桶</div>
<div>睡得跟猪似的</div>
<div>上班开小差</div>
<div>又懒床了</div>
</div>
<script>
window.onload=function(){
//获取div1
var oDiv = document.getElementById('div1');
var aBtn = oDiv.getElementsByTagName('input');
var aDiv = oDiv.getElementsByTagName('div');
for(var i=0; i<aBtn.length; i++){
aBtn[i].index = i;
aBtn[i].onclick=function(){
//点击之前,先清除之前的样式
for(var j = 0; j < aBtn.length; j++){
aBtn[j].className = '';
aDiv[j].style.display = 'none';
}
this.className = 'active';
aDiv[this.index].style.display = 'block';
}
}
};
</script>
</body>
</html>
本文标题:选项卡功能
本文链接:https://www.haomeiwen.com/subject/wyyigttx.html
网友评论