zsydgithub 1 an în urmă
părinte
comite
342d0e89de
2 a modificat fișierele cu 93 adăugiri și 1 ștergeri
  1. 1 1
      Dom/2_demo.html
  2. 92 0
      Dom/3_选项卡.html

+ 1 - 1
Dom/2_demo.html

@@ -6,7 +6,7 @@
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
   <style>
-    #div1{
+    #div1{ 
       width: 200px;
       height: 200px;
       background: red;

+ 92 - 0
Dom/3_选项卡.html

@@ -0,0 +1,92 @@
+<!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>
+    * {
+      margin: 0;
+      padding: 0;
+    }
+
+    ul {
+      list-style: none;
+    }
+
+    #btn {
+      overflow: hidden;
+    }
+
+    li {
+      width: 50px;
+      height: 30px;
+      border: 1px solid #ccc;
+      text-align: center;
+      line-height: 30px;
+      border-radius: 10px;
+      background: aqua;
+      float: left;
+    }
+
+    #div1 {
+      width: 400px;
+      height: 200px;
+      border: 1px solid #ccc;
+    }
+
+    .selected {
+      color: white;
+      background: orange;
+    }
+
+    .active {
+      display: none;
+    }
+
+    .select {
+      display: block;
+    }
+  </style>
+</head>
+
+<body>
+  <div id="container">
+    <ul id="btn">
+      <li class="selected">时事</li>
+      <li>新闻</li>
+      <li>体育</li>
+    </ul>
+    <div id="div1">
+      <div class="active select">时事内容</div>
+      <div class="active">新闻内容</div>
+      <div class="active">体育内容</div>
+    </div>
+  </div>
+  <script>
+    var btns = document.getElementsByTagName('li')
+    var content = document.getElementsByClassName('active')
+
+    for (var i = 0; i < btns.length; i++) {
+      btns[i].index = i
+      console.log(btns[i].index)
+      btns[i].onclick = function () {
+        for (var j = 0; j < btns.length; j++) {
+          btns[j].className = ' '
+          content[j].className = 'active'
+        }
+
+        // console.log(this.index)
+
+        //谁的点击事件就是谁  btn[i].onclick    btns[]
+        this.className = 'selected'
+        //content[索引值] = content[btns点击谁的索引值] =content[this.index]
+        content[this.index].className = 'active select'
+      }
+    }
+  </script>
+</body>
+
+</html>