• 点击按钮切换内容


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
        #div1 div{
             200px;height: 200px;
            border:1px solid #999;
            display: none;
        }
        .active{
            background:red;
        }
        </style>
    </head>
    <body>
        <div id="div1">
            <input class="active" type="button" value="1">
            <input type="button" value="2">
            <input type="button" value="3">
            <div style="display: block;">111111111111</div>
            <div >222222222222</div>
            <div >333333333333</div>
    
        </div>
    
        <script>
        window.onload = function(){
            var t1 = new Tab();
            t1.init();
        }
        // 全局变量就是属性
        function Tab(){
            this.oParent = document.getElementById("div1");
            this.aInput = this.oParent.getElementsByTagName("input");
            this.aDiv = this.oParent.getElementsByTagName("div");
        }
    // 函数就是方法
        Tab.prototype.init = function(){
            var This = this; 
            console.log(111,this)
            for(var i=0 ; i < this.aInput.length; i++){
                this.aInput[i].index = i;
    
                this.aInput[i].onclick = function(){
                    console.log(222,this)
    
                    // This.change(this);
                     for(var i=0 ; i < This.aInput.length; i++){
                            This.aInput[i].className = "";
                             This.aDiv[i].style.display = "none";
                         }
                         this.className = "active";
                         This.aDiv[this.index].style.display = "block";
                     }
            
                }
            }
    
        </script>
    </body>
    </html>
  • 相关阅读:
    Linux系统管理10-----进程和计划任务管理
    07作业进程和任务管理
    Linux系统管理09-----引导过程与服务过程
    网站部署流程
    Docker 安装与使用
    基于NFS共享实现kvm虚拟主机
    GlusterFS 部署
    rsync 远程同步服务部署
    Zabbix 通过 JMX 监控 tomcat
    Zabbix 简单错误 解决方法
  • 原文地址:https://www.cnblogs.com/dexin/p/6489974.html
Copyright © 2020-2023  润新知