代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>选项卡应用</title>
<style>
.box div{
display: none;
border:1px solid #000;
width: 200px;
height: 200px
}
.on{color: #fff;background: tomato}
</style>
</head>
<body>
<script>
// 选项卡
class Tab{ //步骤2
constructor(id){
this.oBox = document.getElementById(id);
this.aBtn = this.oBox.getElementsByTagName('input')
this.aDiv = this.oBox.getElementsByTagName('div')
this.init()
}
init(){ //步骤3
for (let i = 0; i < this.aBtn.length; i++) {
this.aBtn[i].onclick=function(){
// alert(this);
this.hide();
this.show(i);
}.bind(this) //矫正this指向
}
}
hide(){
for (let i = 0; i < this.aBtn.length; i++) {
this.aBtn[i].className=''
this.aDiv[i].style.display='none'
}
}
show(dd){
this.aBtn[dd].className='on';
this.aDiv[dd].style.display='block'
}
}
// 这几行为:继承
// class AutoTab extends Tab{
// }
// window.onload = function(){
// new Tab('box')
// new AutoTab('box2')
// }
window.onload = function(){
new Tab('box') // 步骤1
}
</script>
<div id="box" class="box">
<input type="button" value="aaa" class="on">
<input type="button" value="bbb">
<input type="button" value="ccc">
<div style="display:block">111</div>
<div>222</div>
<div>333</div>
</div>
<div id="box2" class="box">
<input type="button" value="aaa" class="on">
<input type="button" value="bbb">
<input type="button" value="ccc">
<div style="display:block">111</div>
<div>222</div>
<div>333</div>
</div>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。