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

  • 相关阅读:
    点双连通分量模板
    Caocao's Bridges HDU
    边双连通分量模板
    夏令营501-511NOIP训练18——高三楼
    夏令营501-511NOIP训练17——蛇形矩阵
    夏令营501-511NOIP训练16——数字转换
    模板——最小费用最大流
    洛谷P1792——[国家集训队]种树
    XJOI夏令营501-511NOIP训练14——好朋友
    codeforces 1178E-Archaeology
  • 原文地址:https://www.cnblogs.com/520yh/p/12981618.html
Copyright © 2020-2023  润新知