标签:
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>
标签:
原文地址:http://www.cnblogs.com/Vito-L/p/4625506.html