3 Star 6 Fork 1

tutu/ESC6

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
选项卡应用1.html 2.35 KB
一键复制 编辑 原始数据 按行查看 历史
tutu 提交于 2018-09-11 17:40 +08:00 . first ES6
<!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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/huangjuntu/ESC6.git
git@gitee.com:huangjuntu/ESC6.git
huangjuntu
ESC6
ESC6
master

搜索帮助