最简单的tab选项卡

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Tab选项卡</title>
    <style>
      .container {
        max-width: 800px;
        margin: 30px auto;
        border-radius: 4px;
        box-shadow: 0 0 4px 0px rgba(0, 0, 0, 0.3);
        padding: 16px;
      }
      .tabs .tab-header {
        display: flex;
        font-size: 13px;
        color: #303030;
        line-height: 30px;
        font-weight: 500;
        border-bottom: 2px solid #ddd;
      }
      .tabs .tab-item {
        margin-right: 30px;
        margin-bottom: -2px;
        cursor: pointer;
      }

      .tabs .tab-item.active {
        color: #409eff;
        border-bottom: 2px solid red;
      }

      .tabs .tab-panel {
        padding: 16px 0;
        font-size: 14px;
        display: none;
      }

      .tabs .tab-panel.active {
        display: block;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h2>Tab选项卡</h2>
      <div class="tabs">
        <div class="tab-header">
          <span class="tab-item active">用户管理</span>
          <span class="tab-item">配置管理</span>
          <span class="tab-item">角色管理</span>
          <span class="tab-item">定时任务补偿</span>
        </div>
        <div class="tab-content">
          <div class="tab-panel active">111</div>
          <div class="tab-panel">222</div>
          <div class="tab-panel">333</div>
          <div class="tab-panel">4444</div>
        </div>
      </div>
    </div>

    <script>
      const tabItems = document.querySelectorAll(".tabs .tab-item");
      const tabPanels = document.querySelectorAll(".tabs .tab-panel");

      tabItems.forEach((tabItem) => {
        tabItem.onclick = function () {
          tabItems.forEach((tabItem) => tabItem.classList.remove("active"));
          this.classList.add("active");

          let index = [...tabItems].indexOf(this);
          tabPanels.forEach((panel) => {
            panel.classList.remove("active");
          });
          tabPanels[index].classList.add("active");
        };
      });
    </script>
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值