1 <!-- 定时器属于BOM浏览器对象模型是操作浏览器的一些方法,在JavaScript中的作用:
2 1、制作动画
3 2、异步操作
4 3、函数缓冲和节流
5 两种定时器:
6 1、只执行一次的定时器
7 开启:setTimeout 关闭:clearTimeout
8 2、反复执行的定时器
9 开启:setInterval 关闭:clearInerval -->
10 <!DOCTYPE html>
11 <html lang="en">
12 <head>
13 <meta charset="UTF-8">
14 <title>Document</title>
15 <script type="text/javascript">
16 function myalter(){
17 alert('hello world!');
18 }
19 // var timer01 = setTimeout(myalter, 2000);
20 /*
21 var timer01 = setTimeout(function(){
22 alert('hello world!');
23 }, 2000);
24 */
25 // setTimeout(myalter, 2000) 参数一可以是函数名,也可以是一个匿名函数,参数二数值,表示多少毫秒;
26 // clearTimeout(timer01); //不会再弹出,因为还没有到2s就已经被关闭了;
27
28 var timer02 = setInterval(myalter,1000);
29 clearInterval(timer02);
30 </script>
31 </head>
32 <body>
33
34 </body>
35 </html>