码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript时钟实例

时间:2015-07-06 23:13:05      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title>Date</title>
 6 </head>
 7 <body onload="startTime()">
 8 <script>
 9     function startTime(){
10         var today = new Date();
11         var h = today.getHours();
12         var m = today.getMinutes();
13         var s = today.getSeconds();
14         m = checkTime(m);
15         s = checkTime(s);
16         document.getElementById("timetxt").innerHTML=h+":"+m+":"+s;
17         t = setTimeout(function () {//设置超时时间,500毫秒刷新一次
18             startTime();
19         },500);
20     }
21     function checkTime(i){//检查分钟和秒,如果小于10,则在前面补0,如:01,02...
22         if(i<10){
23             i = "0"+i;
24         }
25         return i;
26     }
27 </script>
28 <div id="timetxt"></div>
29 </body>
30 </html>

 

JavaScript时钟实例

标签:

原文地址:http://www.cnblogs.com/Vito-L/p/4625506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!