zoukankan      html  css  js  c++  java
  • 面向对象选项卡

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css" media="screen">
    .on{background: #f60; color: #fff}
    .box div{ 200px;height: 200px;
    border:1px solid #000;display: none}
    </style>
    </head>
    <body>
    <div id="box" class="box">
    <input class="on" type="button" value="aaa">
    <input type="button" value="bbb">
    <input type="button" value="ccc">
    <div style="display: block">aaaa</div>
    <div>bbbb</div>
    <div>cccc</div>
    </div>
    <div id="box2" class="box">
    <input class="on" type="button" value="aaa">
    <input type="button" value="bbb">
    <input type="button" value="ccc">
    <div style="display: block">aaaa</div>
    <div>bbbb</div>
    <div>cccc</div>
    </div>
    <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 = function(){
    this.iNow=i
    ; this.hide();
    this.show(i);
    document.title=this.iNow;
    }.bind(this);
    }
    }
    hide(){
    for(let i=0;i<this.aBtn.length;i++){
    this.aBtn[i].className='';
    this.aDiv[i].style.display='none';
    }
    }
    show(index){
    this.aBtn[index].className = 'on';
    this.aDiv[index].style.display='block';
    }
    }
    //继承
    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 = function(){
    new Tab('box');
    var at=new AutoTab('box2');
    }
    </script>
    </body>
    </html>

  • 相关阅读:
    shell预备知识
    php session和cookie
    php数据库访问抽象层PDO
    递归求斐波那契数
    SqlDataReader的使用
    DataAdapter与DataSet的使用
    CLR
    Android Studio javadoc 生成注释文档
    MySQL教程之concat以及group_concat的用法
    一文读懂MQTT协议
  • 原文地址:https://www.cnblogs.com/qdcnbj/p/8073886.html
Copyright © 2011-2022 走看看