• 选项卡切换


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>选项卡切换</title>
    <style type="text/css">
    #tab input {
        background: #999;
        border: 1px solid #F00;
    }
    #tab .active {
        background: #000;
        color:#FFF;
    }
    #tab div {
        width:400px; 
        height:300px; 
        display:none;
        padding: 10px;
        background: #CCC;
        border: 1px solid #F00;
    }
    </style>
    </head>
    
    <body>
    <script type="text/javascript">       
    window.onload = function(){
        var tab = new Tab("tab");
    }
    
    function Tab(id){
        var _this = this;
        var tabBox = document.getElementById(id);
        this.tabBtn = tabBox.getElementsByTagName('input');
        this.tabDiv = tabBox.getElementsByTagName('div');
        //console.log(this);
        for(var i=0;i<this.tabBtn.length;i++){
            this.tabBtn[i].index = i;
            this.tabBtn[i].onclick = function(){
                 //注意参数this代表的是this.tabBtn[i],即input按钮
                 _this.clickBtn(this);
            };
        }
    };
     //将点击的按钮以参数的形式传入
    Tab.prototype.clickBtn = function(an){
        for(var j=0;j<this.tabBtn.length;j++){
        this.tabBtn[j].className='';
        this.tabDiv[j].style.display='none';
        }
        an.className='active';
        this.tabDiv[an.index].style.display='block';
    };
     
    </script>
    <body>
        <div id="tab">
            <input type="button" value="1" class="active" />
            <input type="button" value="2" />
            <input type="button" value="3" />
            <div style="display:block;">1111111</div>
            <div>22222222</div>
            <div>33333333</div>
        </div>
    </body>
    </html>
  • 相关阅读:
    压测 swoole_websocket_server 性能
    Laravel本地环境搭建:Homestead开发环境的部署
    laravel5.5框架中视图间如何共享数据?视图间共享数据的两种方法
    laravel框架模型model的创建与使用方法
    laravel学习:主从读写分离配置的实现
    《梦断代码》阅读笔记一
    数组结对开发
    对搜狗输入法的评价
    几个一
    对于大家的评审提出改进方案
  • 原文地址:https://www.cnblogs.com/gaobint/p/7774933.html
Copyright © 2020-2023  润新知