|
@@ -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>
|