(002)定时器

 1 <html>
 2     <head>
 3         <meta http-equiv="content-Type" content="text/html;charset=utf-8">
 4         <script type="text/javascript">
 5 
 6             var timer = null;
 7 
 8             function show() {
 9                 alert("test");
10             }
11 
12             window.onload = function() {
13                 
14                 var startTimerBtn = document.getElementById("startTimerBtn");
15                 var stopTimerBtn = document.getElementById("stopTimerBtn");
16 
17                 startTimerBtn.onclick = function() {
18                     timer = setInterval(show,1000);
19                 };
20 
21                 stopTimerBtn.onclick = function() {
22                     clearInterval(timer);
23                 };
24             }
25         </script>
26     </head>
27     <body>
28         <input type="button" id="startTimerBtn" value="开启定时器">
29         <input type="button" id="stopTimerBtn" value="结束定时器">
30     </body>
31 </html>

 

posted @ 2013-11-25 22:07  雪中飞雁  阅读(59)  评论(0)    收藏  举报