zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    pip相关工具使用小结
    PyCharm配置autopep8,自动格式化Python代码
    PyCharm运行Nosetests并导出测试报告
    Jenkins集成taffy进行自动化测试并输出测试报告
    Locust性能测试框架,从入门到精通
    浅谈如何打造一个安全稳定高效的容器云平台
    微服务治理平台的RPC方案实现
    这个需求我不接之事务的自动补偿
    微服务熔断隔离机制及注意事项
    容器化-Docker介绍
  • 原文地址:https://www.cnblogs.com/dekui/p/9008565.html
Copyright © 2011-2022 走看看