选项卡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>选项卡</title>
    <style type="text/css">
        input{background: white;}
        .active{background: yellow;}
        div{width:200px;height: 100px;background: #ccc;display: none;}
    </style>
    <script type="text/javascript">
    window.onload=function(){
        var aBtn=document.getElementsByTagName('input');
        var aDiv=document.getElementsByTagName('div');
        
        var i=0;
        for (i = 0; i < aBtn.length; i++) {
            aBtn[i].index=i;
            aBtn[i].onclick=function(){
                for(i=0;i<aBtn.length;i++){
                    aBtn[i].className='';
                    aDiv[i].style.display='none';
                }
                // alert(this.index);
                aDiv[this.index].style.display="block";
                this.className='active';
            }
        };
    }
    </script>
</head>
<body>
    <input type="button" class="active" value="1" >
    <input type="button" value="2">
    <input type="button" value="3">
    <div style="display:block">111</div>
    <div>222</div>
    <div>333</div>
</body>
</html>

 

查看范例

posted @ 2017-01-16 16:43  Mr_W_Blog  阅读(149)  评论(0编辑  收藏  举报