e 1 年之前
父节点
当前提交
c5606e3248
共有 2 个文件被更改,包括 115 次插入0 次删除
  1. 31 0
      JS初级/BOM/2.Math对象.html
  2. 84 0
      JS初级/BOM/3.window.html

+ 31 - 0
JS初级/BOM/2.Math对象.html

@@ -0,0 +1,31 @@
+<!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>
+    <!-- 
+        var 定义变量 
+        var a = 1;
+        字面量
+        1 2 3 4 6 true
+     -->
+    <script>
+        document.write(Math.PI+'<br>'); // Math.PI => Π 常量
+        document.write(Math.E);// 常量 固定值
+        console.log(Math.ceil(2.167)); // 向上取整
+        console.log(Math.floor(93.1)); // 向下取整
+        console.log(Math.abs(-90)); // 绝对值
+        console.log(Math.round(2.1)); //四舍五入
+        console.log(Math.random()*10); // 随机数
+        // 固定范围内随机数 Math.random()*(y-x)+x
+        console.log(Math.random()*(4)+1)
+        // 固定范围内随机数  Math.round(Math.random()*(y-x)+x)
+        console.log(Math.round(Math.random()*(9)+11));
+        console.log(Math.pow(3,6));//获取x的y次幂
+        console.log(Math.sqrt(81)); //获取x的算术平方根
+    </script>
+</body>
+</html>

+ 84 - 0
JS初级/BOM/3.window.html

@@ -0,0 +1,84 @@
+<!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>
+        #btn1 {
+            width: 180px;
+            padding: 20px;
+            background: #f00;
+            color: #ff0;
+            text-align: center;
+        }
+        #btn2 {
+            width: 180px;
+            padding: 20px;
+            background: #00f;
+            color: #0f0;
+            text-align: center;
+            margin-top: 20px;
+        }
+        #btn3 {
+            width: 180px;
+            padding: 20px;
+            background: #f00;
+            color: #ff0;
+            text-align: center;
+            margin-top: 40px;
+        }
+        #btn4 {
+            width: 180px;
+            padding: 20px;
+            background: #00f;
+            color: #0f0;
+            text-align: center;
+            margin-top: 20px;
+        }
+    </style>
+</head>
+<body>
+    <div id="btn1">这是一个开始按钮</div>
+    <div id="btn2">这是一个结束按钮</div>
+    <div id="btn3">这是一个新的按钮</div>
+    <div id="btn4">这是一个旧的按钮</div>
+    <!-- 
+        setInterval 定时器 规定时间内执行函数  setInterval(函数,时间)
+        clearInterval 清除定时器
+        setTimeout  延时器 规定时间后执行一次函数 setTimeout(函数,时间)
+     -->
+    <script>
+        // window.alert() => alert()
+        //  window.alert("警告框");
+        // window.confirm() => confirm()
+        //  window.confirm("确认框");
+        // window.prompt() => prompt()
+        //  window.prompt("提示框");
+        var timer1;
+        // 获取按钮
+        var btn1 = document.getElementById("btn1");
+        btn1.onclick = function() {
+           timer1 = setInterval(function(){
+                console.log("执行一次")
+            },500)
+        }
+        var btn2 = document.getElementById("btn2");
+        btn2.onclick = function() {
+            clearInterval(timer1)
+        }   
+        var timer2;
+        var btn3 = document.getElementById("btn3");
+        btn3.onclick = function() {
+          timer2 = setTimeout(function(){
+                console.log("这是新的按钮");
+            },3000)
+        }
+        var btn4 = document.getElementById("btn4");
+        btn4.onclick = function() {
+            clearTimeout(timer2);
+            alert("成功了");
+        }
+    </script>
+</body>
+</html>