页面时间显示一个钟表

代码
1 <html>
2  <head>
3 <script type="text/javascript">
4 function startTime()
5 {
6 var today=new Date();
7 var h=today.getHours();
8 var m=today.getMinutes();
9 var s=today.getSeconds();
10
11 m=checkTime(m);
12 s=checkTime(s);
13 document.getElementById('txt').innerHTML=h+":"+m+":"+s;
14 t=setTimeout('startTime()',500);
15 }
16
17 function checkTime(i)
18 {
19 if(i<10)
20 {
21 i="0"+i;
22 }
23 return i;
24 }
25 </script>
26 </head>
27 <body onload="startTime()">
28 <div id="txt">
29 </div>
30 </body>
31 </html>
posted @ 2010-10-12 16:11  xfyn  阅读(155)  评论(0编辑  收藏  举报