2020-11-25 09:34:06 版本 : JS实现的简单tab切换功能完整示例
作者: 周杨 于 2020年11月25日 发布在分类 / 计算机应用 / 编程 下,并于 2020年11月25日 编辑
 历史版本

备注 修改日期 修改人
CREAT 2020-11-25 09:34:06[当前版本] 系统管理员

转自:https://www.jb51.net/article/163507.htm

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>www.jb51.net tab切换</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      body {
        font-size: 12px;
      }
      ul,
      li,
      ol {
        list-style: none;
      }
      a {
        text-decoration: none;
      }
      .clearfix {
        clear: both;
        overflow: hidden;
      }
      .tab_title ul li {
        float: left;
        padding: 0 10px;
      }
    </style>
  </head>
  <body>
    <div id="Tab1" class="tab clearfix">
      <div class="tab_title clearfix">
        <ul>
          <li>
            <a
              target="_self"
              href="#"
              rel="external nofollow"
              rel="external nofollow"
              rel="external nofollow"
              onmouseover="setTab('one',1,3)"
              id="one1"
              >TAB1</a
            >
          </li>
          <li>
            <a
              target="_self"
              href="#"
              rel="external nofollow"
              rel="external nofollow"
              rel="external nofollow"
              onmouseover="setTab('one',2,3)"
              id="one2"
              >TAB2</a
            >
          </li>
          <li>
            <a
              target="_self"
              href="#"
              rel="external nofollow"
              rel="external nofollow"
              rel="external nofollow"
              onmouseover="setTab('one',3,3)"
              id="one3"
              >TAB3</a
            >
          </li>
        </ul>
      </div>
      <div class="tab_details clearfix">
        <div id="con_one_1" style="display: block">con_one_1</div>
        <div style="display: none" id="con_one_2">con_one_2</div>
        <div style="display: none" id="con_one_3">con_one_3</div>
      </div>
    </div>
    <script type="text/javascript">
      //tab切换效果
      function setTab(name, cursel, n) {
        for (var i = 1; i <= n; i++) {
          var menu = document.getElementById(name + i);
          var con = document.getElementById("con_" + name + "_" + i);
          menu.className = i == cursel ? "cur" : "";
          con.style.display = i == cursel ? "block" : "none";
        }
      }
    </script>
  </body>
</html>


运行结果:


历史版本-目录  [回到顶端]
    知识分享平台 -V 5.1.4 -大信谛威