• ES6 class 继承 与面向对象封装开发简单实例


    <!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;
                 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>
  • 相关阅读:
    多表头GridView
    Updater Application Block自动更新实施方案[源代码]
    IE和Firefox的Javascript兼容性总结
    JavaScript IE加速
    GridView汇总
    Oracle 中取当前日期的上个月最后天和第一天
    Atitit,通过pid获取进程文件路径 java php  c#.net版本大总结
    Atitit. 数据库catalog与schema的设计区别以及在实际中使用 获取数据库所有库表 java jdbc php  c#.Net
    Atitit. 数据约束 校验 原理理论与 架构设计 理念模式java php c#.net js javascript mysql oracle
    Atitit.一些公司的开源项目 重大知名开源项目attilax总结
  • 原文地址:https://www.cnblogs.com/dekui/p/9008565.html
Copyright © 2020-2023  润新知