周期性定时器,一次性定时器

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>window对象</title>
 6 <script>
 7     //调用window对象的属性或方法,可以省略"window."
 8     //弹出框
 9     function f1() {
10         alert("你好");
11     }
12     function f2() {
13         var b = confirm("你吃了吗?");
14         console.log(b);
15     }
16     function f3() {
17         var v = prompt("你吃的啥?");
18         console.log(v);
19     }
20     //周期性定时器
21     function f4() {
22         //启动定时器,让浏览器每1000毫秒调用一次函数.
23         //该方法返回定时器的ID,此ID用于停止此定时器.
24         var n = 5;
25         var id = setInterval(function(){
26             console.log(n--);
27             if(n<0) {
28                 clearInterval(id);
29                 console.log("DUANG");
30             }
31         },1000);
32         //启动定时器就相当于启动了一个支线程,
33         //而当前方法f4相当于主线程,2个线程是
34         //并发执行的,不互相等待.因此f4方法在
35         //启动了定时器后,立刻执行输出BOOM的代码,
36         //而定时器却是在1000毫秒后才执行第一次.
37         console.log("BOOM");
38     }
39     //一次性定时器
40     var id;
41     function f5() {
42         //启动定时器,让浏览器在10000毫秒后调用该函数.
43         //浏览器调用函数后,该定时器会自动停止.
44         id = setTimeout(function(){
45             console.log("叮叮叮叮叮");
46         },10000);
47     }
48     function f6() {
49         clearTimeout(id);
50     }
51 </script>
52 </head>
53 <body>
54     <p>
55         <input type="button" value="按钮1" onclick="f1();"/>
56         <input type="button" value="按钮2" onclick="f2();"/>
57         <input type="button" value="按钮3" onclick="f3();"/>
58     </p>
59     <p>
60         <input type="button" value="倒数" onclick="f4();"/>
61         <input type="button" value="提醒" onclick="f5();"/>
62         <input type="button" value="取消" onclick="f6();"/>
63     </p>
64 </body>
65 </html>
mysql
原文地址:https://www.cnblogs.com/excellent-vb/p/7729299.html