tab栏切换,排他思想。

    <script>
      //获取元素
      var spanList = document.querySelectorAll("span");
      var liList = document.querySelectorAll("li");
      //遍历每个span
      for (let i = 0; i < spanList.length; i++) {
        // 注册事件
        spanList[i].onclick = function () {
          for (let j = 0; j < spanList.length; j++) {
            //排他思想
            if (j == i) {
              spanList[j].className = "current";
              liList[j].style.display = "block";
            } else {
              spanList[j].className = "";
              liList[j].style.display = "none";
            }
          }
        };
      }
```
                    
                    

你可能感兴趣的:(tab栏切换,排他思想。)