fengchuanyu 1 주 전
부모
커밋
719bbde1d8
3개의 변경된 파일120개의 추가작업 그리고 0개의 파일을 삭제
  1. 28 0
      4_BOM&DOM/20_DOM元素控制.html
  2. 22 0
      4_BOM&DOM/21_文本框控制.html
  3. 70 0
      4_BOM&DOM/练习题8_进度条.html

+ 28 - 0
4_BOM&DOM/20_DOM元素控制.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>
+</head>
+<body>
+    <div class="box"></div>
+    <button>按钮</button>
+    <script>
+        // 获取元素
+        var btn = document.querySelector("button");
+        var box = document.querySelector(".box");
+
+        btn.onclick = function(){
+            // box.innerHTML = "<h1>hello world</h1>"
+            // 创建DOM元素
+            var newDom = document.createElement("h1");
+            // 控制元素与之前方式相同
+            newDom.innerText = "hello world";
+            newDom.style.color = "red";
+            // 将新创建的元素添加到指定的地方
+            box.appendChild(newDom);
+        }
+    </script>
+</body>
+</html>

+ 22 - 0
4_BOM&DOM/21_文本框控制.html

@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <input type="text" placeholder="请输入数字">
+    <button>按钮</button>
+    <script>
+        var inp = document.querySelector("input");
+        var btn = document.querySelector("button");
+        btn.onclick = function(){
+            // 获取文本框内的值
+            var val = inp.value;
+            console.log(val)
+            inp.value = "";
+        }
+    </script>
+</body>
+</html>

+ 70 - 0
4_BOM&DOM/练习题8_进度条.html

@@ -0,0 +1,70 @@
+<!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>
+        .progress-content {
+            width: 500px;
+            height: 80px;
+            border: 5px solid black;
+            border-radius: 10px;
+            position: relative;
+            overflow: hidden;
+        }
+
+        .progress-content .progress-bg {
+            width: 0;
+            height: 80px;
+            background-color: orange;
+        }
+
+        .progress-num {
+            color: #999;
+            font-size: 40px;
+            font-weight: bold;
+            position: absolute;
+            top: 0;
+            left: 20px;
+            height: 80px;
+            line-height: 80px;
+        }
+    </style>
+</head>
+
+<body>
+    <div class="progress-content">
+        <div class="progress-bg"></div>
+        <div class="progress-num">
+            0%
+        </div>
+    </div>
+    <button>开始</button>
+    <script>
+        // 获取元素
+        var progressNum = document.querySelector(".progress-num");
+        var progressBg = document.querySelector(".progress-bg");
+        var btn = document.querySelector("button");
+        var timer = 0;
+        // 按钮绑定事件
+        btn.onclick = function () {
+            var num = 0;
+            // 进度条动画
+            timer = setInterval(function () {
+                if (num >= 100) {
+                    clearInterval(timer);
+                } else {
+                    num++;
+                    progressBg.style.width = num + "%";
+                    progressNum.innerText = num + "%";
+                }
+            }, 16)
+        }
+
+
+    </script>
+</body>
+
+</html>