zoukankan      html  css  js  c++  java
  • js面向对象实现Tab切换

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            input {
                width: 200px;
                height: 20px;
                background: white;
            }
    
            input.active {
                background: yellow;
            }
    
            #div1 div {
                width: 200px;
                height: 200px;
                background-color: #cccccc;
                display: none;
            }
        </style>
    </head>
    
    <body>
        <div id="div1">
            <input type="button" value="a">
            <input type="button" value="b">
            <input type="button" value="c">
            <div class="dv">a</div>
            <div class="dv">b</div>
            <div class="dv">c</div>
        </div>
    </body>
    <script>
        
        window.onload = function () {
            new TabSwitch('div1')
        }
        function TabSwitch(id) {
            var _this = this;
            var oDiv1 = document.getElementById(id);
    
            this.bTn = document.getElementsByTagName('input');
            this.aDiv = document.getElementsByClassName('dv');
    
            document.getElementsByTagName('input')[0].className = 'active';
            document.getElementsByClassName('dv')[0].style.display = 'block';
    
            for (var i = 0; i < this.bTn.length; i++) {
                this.bTn[i].index = i;
                this.bTn[i].onclick = function () {
                    _this.fnClick(this);
                }
            }
        };
        
        TabSwitch.prototype.fnClick = function (oBtn) {
            for (var i = 0; i < this.bTn.length; i++) {
                this.bTn[i].className = '';
                this.aDiv[i].style.display = 'none';
            }
            oBtn.className = 'active';
            this.aDiv[oBtn.index].style.display = 'block';
        }
    </script>
    
    </html>

  • 相关阅读:
    curl 设置超时时间
    allure 2
    shell 给文件每一行都添加指定字符串
    shell 文件的包含
    shell 求数组的平均值,求和,最大值,最小值
    shell 编写进度条
    shell 换行与不换行
    Linux常用命令简述--dirname与basename
    shell中脚本参数传递getopts
    Shell 中eval的用法
  • 原文地址:https://www.cnblogs.com/520yh/p/12981618.html
Copyright © 2011-2022 走看看