zsydgithub 2 years ago
parent
commit
2e1e3ad02b
3 changed files with 115 additions and 1 deletions
  1. 1 1
      6_Dom/1_基础.html
  2. 32 0
      6_Dom/2_demo.html
  3. 82 0
      6_Dom/3_选项卡.html

+ 1 - 1
6_Dom/1_基础.html

@@ -59,7 +59,7 @@
     var li1 = ul2.getElementsByClassName('xxx')
     console.log(ul1)
     console.log(xxx)
-    console.log(div1)
+    console.log(div1) 
     btn.onclick = function(){
       div1.style.background = 'green'
       console.log(123)

+ 32 - 0
6_Dom/2_demo.html

@@ -0,0 +1,32 @@
+<!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>
+    #div1{
+      width: 200px;
+      height: 200px;
+      background: red;
+      left: 100px;
+      top: 500px;
+      position: absolute;
+    }
+  </style>
+</head>
+<body>
+  <div id="div1"></div>
+  <button id="btn">点击</button>
+  <script>
+    var div1 = document.getElementById('div1')
+    var btn = document.getElementById('btn')
+    btn.onclick =function(){
+      div1.style.background = 'green'
+      div1.style.left = 400 + 'px'
+      div1.style.top = '100px'
+    }
+  </script>
+</body>
+</html>

+ 82 - 0
6_Dom/3_选项卡.html

@@ -0,0 +1,82 @@
+<!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;
+      background: aqua;
+      text-align: center;
+      line-height: 30px;
+      border: 1px solid #ccc;
+      float: left;
+      border-radius: 10px;
+    }
+    #div1{
+      width: 400px;
+      height: 200px;
+      border: 1px solid #ccc;
+    }
+    .selected{
+      color: white;
+      background: orange;
+    }
+    .actived{
+      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="actived select">时事内容</div>
+      <div class="actived">新闻内容</div>
+      <div class="actived">体育内容</div>
+    </div>
+  </div>
+  <script>
+    var btn = document.getElementsByTagName('li')
+    var content = document.getElementsByClassName('actived')
+
+    console.log(btn)
+    console.log(content)
+    for(var i=0;i<btn.length;i++){
+      btn[i].index = i
+      console.log(btn[i].index)
+      btn[i].onclick = function(){
+        for(var j=0;j<btn.length;j++){
+          btn[j].className = ''
+          content[j].className = 'actived'
+          
+        }
+        //this = btn[点击哪个是哪个]     btn[点击哪个就是哪个].index = 点击哪个就是那个
+        this.className = 'selected'
+        //content[点击哪个就是哪个] = content[btn[点击哪个就是哪个].index] = content[this.index]
+        content[this.index].className = 'actived select'
+      }
+    }
+  </script>
+</body>
+</html>