<!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>

最新文章

  1. OneThink-nav标签
  2. redis 集群创建常见几个问题
  3. 数组栈的C语言实现
  4. 【源码分享】WPF漂亮界面框架实现原理分析及源码分享
  5. [zt]摄像机标定(Camera calibration)笔记
  6. C++编程优化心得(持续更新)
  7. asp.net ajax 调用一例
  8. 【转】Oracle 执行动态语句
  9. mysql 用户方面的操作
  10. Hadoop伪分布模式配置
  11. byte[] 清空
  12. codeforce447 D SGU 548 贪心+优先队列
  13. STL的简介
  14. c#执行Dos命令
  15. last期末作业
  16. [入门向选讲] 插头DP:从零概念到入门 (例题:HDU1693 COGS1283 BZOJ2310 BZOJ2331)
  17. APP,H5测试要点
  18. java 基础 整数类型
  19. 针对开发项目的NABCD的分析
  20. Linux&#160;awk命令常见使用方法介绍

热门文章

  1. 一个简单的C共享库的创建及Python调用此库的方法
  2. Ubuntu防火墙常用命令
  3. 重置node节点
  4. springboot整合es客户端操作elasticsearch(四)
  5. python 其实不用框架你也可以实现ORM
  6. char、varchar、nchar、nvarchar四种类型
  7. windows下,给golang编译的exe添加一个图标
  8. AirFlow功能展示个人笔记
  9. 【Python】【demo实验5】【练习实例】【多个数字组合成不重复三位数】
  10. MySQL_bigint(20) 是什么意思?