ES6 class 继承 与面向对象封装开发简单实例
2024-09-05 09:08:55
<!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>
.active{
background-color: #789218;
color:aqua;
}
.box div{
height: 200px;
width: 200px;
border: 1px solid #cccccc;
display: none;
}
</style>
</head>
<body>
<script>
class Tab{
constructor(id){
this.oBox = document.getElementById(id);
this.aBtn = this.oBox.getElementsByTagName('input');
this.aDiv = this.oBox.getElementsByTagName('div');
this.iNow = 0;
this.init();
}
init(){
for(let i=0;i<this.aBtn.length;i++){
this.aBtn[i].onclick=()=>{
this.iNow = i;
document.title = this.iNow;
this.hide();
this.show(i);
}
}
}
hide(){
for(var i = 0; i < this.aDiv.length;i++){
this.aDiv[i].style.display = 'none';
this.aBtn[i].className = '';
}
}
show(index){
this.aDiv[index].style.display = 'block';
this.aBtn[index].className = 'active';
}
}
class AuToTab extends Tab{
constructor(id){
super(id);
setInterval(this.next.bind(this),1000)
}
next(){
this.iNow++;
if(this.iNow == this.aBtn.length)this.iNow=0;
this.hide();
this.show(this.iNow);
}
}
window.onload=()=>{
new Tab('box');
new AuToTab('box2');
}
</script>
<div id="box" class="box">
<input type="button" value="aaa" class="active">
<input type="button" value="bbb">
<input type="button" value="ccc">
<div style="display: block;">1111</div>
<div>2222</div>
<div>3333</div>
</div>
<div id="box2" class="box">
<input type="button" value="aaa" class="active">
<input type="button" value="bbb">
<input type="button" value="ccc">
<div style="display: block;">1111</div>
<div>2222</div>
<div>3333</div>
</div>
</body>
</html>
最新文章
- OneThink-nav标签
- redis 集群创建常见几个问题
- 数组栈的C语言实现
- 【源码分享】WPF漂亮界面框架实现原理分析及源码分享
- [zt]摄像机标定(Camera calibration)笔记
- C++编程优化心得(持续更新)
- asp.net ajax 调用一例
- 【转】Oracle 执行动态语句
- mysql 用户方面的操作
- Hadoop伪分布模式配置
- byte[] 清空
- codeforce447 D SGU 548 贪心+优先队列
- STL的简介
- c#执行Dos命令
- last期末作业
- [入门向选讲] 插头DP:从零概念到入门 (例题:HDU1693 COGS1283 BZOJ2310 BZOJ2331)
- APP,H5测试要点
- java 基础 整数类型
- 针对开发项目的NABCD的分析
- Linux&#160;awk命令常见使用方法介绍