JS 间隔执行 实例:万年历

setInterval   间隔执行

setInterval(要调用的函数,多少毫秒)

 

源代码

 1 <html>
 2 
 3     <head>
 4         <title></title>
 5         <meta charset="UTF-8">
 6     </head>
 7 
 8     <body>
 9         <span id="sy"></span>&nbsp;&nbsp;
10         <span id="smt"></span>&nbsp;&nbsp;
11         <span id="sd"></span>&nbsp;&nbsp;
12         <span id="sh"></span>&nbsp;&nbsp;
13         <span id="sm"></span>&nbsp;&nbsp;
14         <span id="ss"></span>&nbsp;&nbsp;
15     </body>
16 
17 </html>
18 <script>
19     
20 //    var str = d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日";
21 //    var arr = Array();
22     window.setInterval("sit1()", 500);
23     window.setInterval("sit2()", 500);
24     window.setInterval("sit3()", 500);
25     window.setInterval("sit4()", 500);
26     window.setInterval("sit5()", 500);
27     window.setInterval("sit6()", 500);
28 
29     function sit1() {
30         var d = new Date();
31         document.getElementById('sy').innerText = d.getFullYear();
32     }
33 
34     function sit2() {
35         var d = new Date();
36         document.getElementById('smt').innerText = d.getMonth()+1;
37     }
38     function sit3() {
39         var d = new Date();
40         document.getElementById('sd').innerText = d.getDate();
41     }
42 
43     function sit4() {
44         var d = new Date();
45         document.getElementById('sh').innerText = d.getHours();
46     }
47     function sit5() {
48         var d = new Date();
49         document.getElementById('sm').innerText = d.getMinutes();
50     }
51 
52     function sit6() {
53         var d = new Date();
54         document.getElementById('ss').innerText = d.getSeconds();
55     }
56 </script>

 

效果图

 

posted @ 2017-04-27 20:38  for米洛  阅读(204)  评论(0编辑  收藏  举报