fengchuanyu 3 сар өмнө
parent
commit
a398e7757f

+ 28 - 0
5_DOM/10_添加属性.html

@@ -0,0 +1,28 @@
+<!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>
+        .div1{
+            color: red;
+        }
+    </style>
+</head>
+<body>
+    <div id="box">hello</div>
+    <img >
+    <script>
+        var oBox = document.getElementById("box");
+        var oImg = document.getElementsByTagName("img")[0];
+        // oBox.setAttribute("class","div1");
+        // oBox.class = "div1";
+        // oImg.src = "./image/img1.png";
+        oImg.index = 1;
+        console.log(oImg.index);
+
+
+    </script>
+</body>
+</html>

+ 39 - 0
5_DOM/11_控制类.html

@@ -0,0 +1,39 @@
+<!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: 100px;
+            height: 100px;
+            background-color: red;
+        }
+        .box2{
+            border:3px solid black;
+        }
+        .box3{
+            margin-top: 200px;
+        }
+    </style>
+</head>
+<body>
+    <!-- <div class="box box2"></div> -->
+     <div></div>
+    <script>
+        var oBox = document.getElementsByTagName("div")[0];
+        // oBox.setAttribute("class","box");
+        // 控制标签类名
+        // oBox.className = "box";
+        oBox.className = "box box2";
+
+        // var str = "box2";
+        // oBox.classList.remove("box2");
+        // oBox.classList.add("box2");
+
+        oBox.classList.replace("box2","box3");
+
+    </script>
+</body>
+</html>