e 1 year ago
parent
commit
b9ab85d92d
2 changed files with 113 additions and 0 deletions
  1. 26 0
      js/js初阶/DOM/4.demo.html
  2. 87 0
      js/js初阶/DOM/5.选项卡.html

+ 26 - 0
js/js初阶/DOM/4.demo.html

@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        #box {
+            width: 200px;
+            height: 200px;
+            background: #f00;
+        }
+    </style>
+</head>
+<body>
+    <div id="box"></div>
+    <button>放大</button>
+    <script>
+        var box = document.getElementById("box");
+        var btn = document.querySelector("button");
+        btn.onclick = function() {
+            box.style.width = 600 + "px";
+        }
+    </script>
+</body>
+</html>

+ 87 - 0
js/js初阶/DOM/5.选项卡.html

@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        * {
+            margin: 0;
+            padding: 0;
+            list-style: none;
+            text-decoration: none;
+            box-sizing: border-box;
+        }
+        #container {
+            width: 482px;
+            height: 420px;
+            margin: 100px auto;
+            border: 1px solid #000;
+        }
+        #list {
+            overflow: hidden;
+        }
+        #list li {
+            width: 120px;
+            height: 80px;
+            text-align: center;
+            line-height: 80px;
+            float: left;
+            border: 1px solid #f00;
+        }
+        .selected {
+            color: #ff0;
+            background: #f00;
+        }
+        .choose {
+            display:none;
+        }
+        .active {
+            width: 482px;
+            height: 300px;
+            color: purple;
+            font-weight: bold;
+            text-align: center;
+            line-height: 300px;
+            display: block;
+        }
+    </style>
+</head>
+<body>
+    <div id="container">
+        <ul id="list">
+            <li class="selected">用户管理</li>
+            <li>配置管理</li>
+            <li>角色管理</li>
+            <li>定时任务补</li>
+        </ul>
+        <div id="main">
+            <div class="choose active">用户管理</div>
+            <div class="choose">配置管理</div>
+            <div class="choose">角色管理</div>
+            <div class="choose">定时任务补</div>
+        </div>
+    </div>
+    <script>
+        var list = document.querySelectorAll("ul li");
+        var main = document.querySelectorAll(".choose");
+        console.log(list,main)
+        for(var i=0;i<list.length;i++) {
+            // console.log(i);
+            // 自定义一个属性下标 存储 点击下标
+            list[i].index = i;
+            list[i].onclick = function() {
+                // 点击事件时 this指向当前点击对象
+                // console.log(list[i]);
+                console.log(this.index)
+                for(var j=0;j<main.length;j++) {
+                    list[j].className = "";
+                    main[j].className = "choose";
+                }
+                list[this.index].className = "selected";
+                main[this.index].className = "choose active";
+            }
+        }
+    </script>
+</body>
+</html>