计时器,当时间是个位数时前面补0

 1 <!DOCTYPE HTML>
 2 <html>
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 5 <title>计时器</title>
 6 <script type="text/javascript">
 7   var attime;
 8   function clock(){
 9     var time=new Date();          
10     attime= add0(time.getHours())+":"+add0(time.getMinutes())+":"+add0(time.getSeconds());
11 
12 setInterval(clock,100)
13     document.getElementById("clock").value = attime;
14   }
15   function add0(time){
16       if(time<10){
17           time = ""+"0"+time;
18       }
19       return time;
20   }
21   22 </script>
23 </head>
24 <body>
25 <form>
26 <input type="text" id="clock" size="50"  />
27 </form>
28 </body>
29 </html>

 

posted @ 2017-09-07 21:32  猎八哥FLY  阅读(741)  评论(0编辑  收藏  举报