秒优化显示
如何实现当秒数不足10秒时显示格式为:01,02,03.....59
如何实现当秒数不足10秒时显示格式为:01,02,03.....59
2015-05-01
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>定时器</title> <script type="text/javascript"> var attime; var colorHead,colorFoot; function clock(){ var time=new Date(); var HH = time.getHours(); if(HH<10){HH="0"+HH}; var MM = time.getMinutes(); if(MM<10){MM="0"+MM}; var SS = time.getSeconds(); if(SS<10){SS="0"+SS}; var ww = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"] var nWeek = time.getDay(); attime= HH+":"+MM+":"+SS+" "+ww[nWeek]; document.getElementById("clock").value = attime; } var timer = setInterval(clock,1000); </script> </head> <body> <form> <input type="text" id="clock" size="50" /> </form> </body> </html>
举报