zoukankan      html  css  js  c++  java
  • 选项卡切换

    <!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>
  • 相关阅读:
    Android(java)学习笔记68:使用proguard混淆android代码
    SGU 194 Reactor Cooling
    关于流量有上下界的网络流问题的求解
    关于最小割的求解方法
    HDU 5311 Hidden String
    POJ 3548 Restoring the digits
    POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater
    ZOJ 1967 POJ 2570 Fiber Network
    HDU 1969 Pie
    HDU 1956 POJ 1637 Sightseeing tour
  • 原文地址:https://www.cnblogs.com/gaobint/p/7774933.html
Copyright © 2011-2022 走看看