请输入代码JavaScript新手小白,请大家不要见笑,我想做个类似选项卡的东西,想点击button的时候,对应的内容展现,其他隐藏,但是我的代码出不来结果,看了半天也不知道错在那里,我想知道错在那里,请大神指教,谢谢!
<!DOCTYPE html>
<html>
<head>
<style>
ul>li{display:none;}
.active{display:block;}
</style>
<script>
function m() {
var obut = document.getElementsByTagName("button");
var oli = document.getElementsByTagName("li");
for (var i = 0; i < obut.length; i++) {
obut[i].index = i;
}
if (oli[this.index].style.display == "none") {
document.getElementsByClassName("active").style.display = "none "oli[this.index].ClassName = "active"
}
}
</script>
</head>
<body>
<div id="btn">
<button onclick="m()">box1</button>
<button onclick="m()">box2</button>
<button onclick="m()">box3</button>
<button onclick="m()">box4</button>
</div>
<ul id="box">
<li><div class="active" >box1</div></li>
<li><div >box2</div></li>
<li><div >box3</div></li>
<li><div >box4</div></li>
</ul>
</body>
</html>
相关分类