原生js TAB切换

7 篇文章 0 订阅
5 篇文章 0 订阅
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        img{
            border:0;
        }
        ol, ul ,li{list-style: none;}
        .div-1{
            width: 300px;
            height: 30px;
            background-color: red;
        }
        .div-2{
            width: 300px;
            height: 300px;
            background-color: pink;
            position: absolute;
            top:30px;
            left:0;
            display: none;
        }
        .div-11{
            width: 100px;
            height: 30px;
            background-color:yellow;
            float:left;
            cursor: pointer;
            text-align: center;
            line-height:30px;
        }
        .show{
            display:block;
        }
        .show-1{
            background-color: red;
        }
    </style>

</head>
<body>
    <div>
        <div class="div-1" id="div_1">
            <div class="div-11 show-1">dsada</div>
            <div class="div-11">dsadsa</div>
            <div class="div-11">dsadsa</div>
        </div>
        <div id="div_22">
          <div class="div-2 show">a</div>
          <div class="div-2">s</div>
          <div class="div-2">b</div>
        </div>

    </div>
</body>
</html>
 <script type="text/javascript">
         var div_1=document.getElementById('div_1');
         var div_1Child=div_1.children;
         var div_22=document.getElementById('div_22');
         var div_22Child=div_22.children;
         
         for(var i=0;i<div_1Child.length;i++){
                div_1Child[i].index=i;  
                div_1Child[i].οnclick=function(){
                  for(var j=0;j<div_1Child.length;j++){
                        div_1Child[j].className="div-11";
                      
                        div_22Child[j].className="div-2";
                         
                  }
                
                   div_1Child[this.index].className="div-11 show-1";
                   div_22Child[this.index].className="div-2 show";
                }
         }
    </script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值