fengchuanyu há 4 meses atrás
pai
commit
01173ff2e4
2 ficheiros alterados com 43 adições e 0 exclusões
  1. BIN
      .DS_Store
  2. 43 0
      4_BOM/5_定时器.html

BIN
.DS_Store


+ 43 - 0
4_BOM/5_定时器.html

@@ -0,0 +1,43 @@
+<!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>
+    <script>
+        
+        // setTimeout(function(){},1000);
+        // 接收两个参数,第一个参数是函数 (回调函数),第二个参数是时间 毫秒为单位
+        // 只能执行一次
+        // setTimeout(function(){
+        //     console.log("hello world");
+        // },3000);
+
+        // setInterval(function(){},1000);
+        // 接收两个参数,第一个参数是函数 (回调函数),第二个参数是时间 毫秒为单位
+        // 可以执行多次
+        // 有返回值 返回值为一个数字 代表定时器的id
+        var timer = setInterval(function(){
+            console.log("hello world");
+        },1000);
+        console.log(timer);
+        
+        setTimeout(function(){
+            clearInterval(timer);
+        },3000);
+        // console.log(timer2);
+        
+        // function fn(){
+        //     console.log("hello world");
+            
+        // }
+        // fn()
+        // var fn = function(){
+        //     console.log("hello world");
+        // }
+        // fn()
+    </script>
+</body>
+</html>