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>
  • 相关阅读:
    storm原理写得比较好的文章
    maven设置jdk版本
    项目中记录log4j记录日志
    eclipse jadeclipse配置
    Maven使用说明
    crond不执行原因分析
    空调遥控器图标含义
    window7开放端sqlserver端口
    servlet仿struts参数注入
    cocos 2dx-js3.5整合anySDK
  • 原文地址:https://www.cnblogs.com/gaobint/p/7774933.html
Copyright © 2011-2022 走看看