tab切换

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .title dt {
        float: left;
        width: 100px;
        height: 50px;
        text-align: center;
        line-height: 50px;
        font-size: 22px;
      }
      .title::after {
        content: "";
        display: block;
        clear: both;
      }
      /* .content dt:nth-of-type(n){
            display: none;
        }
        .content dt:nth-of-type(1){
            display: block;
        } */
      /* n  0-3 2-5  */
      .content dt:nth-of-type(n + 2) {
        display: none;
      }
    </style>
  </head>
  <body>
    <dl class="title">
      <dt>标题1</dt>
      <dt>标题2</dt>
      <dt>标题3</dt>
    </dl>

    <dl class="content">
      <dt>内容1</dt>
      <dt>内容2</dt>
      <dt>内容3</dt>
    </dl>
  </body>
</html>
<script>
  console.log(document.getElementsByTagName("dt"));

  var titleList = document.querySelector(".title").children;
  var contentList = document.querySelector(".content").children;
  console.log(titleList);

  //   for(var i=0;i<titleList.length;i++){
  //       titleList[i].onclick = function(){
  //           // 获取点击标题的下标,显示对应content下dt的内容
  //           // console.log(i);
  //           // console.log(this);
  //           for(var j =0;j<titleList.length;j++){
  //               contentList[j].style.display = "none"
  //               if(titleList[j]  == this){
  //                   console.log(j);
  //                   contentList[j].style.display = "block"
  //               }
  //               // else{
  //               //     contentList[j].style.display = "none"
  //               // }
  //           }

  //         // contentList[i].style.display = "block"

  //         // contentList[2].style.display = "block"
  //     }
  // }

  //   let 声明一个 1,块级作用域(就是只在大括号内生效)  2,没有变量提升
  // for (let i = 0; i < titleList.length; i++) {
  //   titleList[i].onclick = function () {
  //     // 获取点击标题的下标,显示对应content下dt的内容
  //     for (var j = 0; j < titleList.length; j++) {
  //       contentList[j].style.display = "none";
  //     }
  //     contentList[i].style.display = "block";
  //   };
  // }

  //   console.log(a);
  //   let a = 1

  //   function demo(){
  //       console.log(a);
  //   }
  //   demo()
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值