因为当小时,分,秒小于10的时候,会省略掉前面那个0。比如09:09:09会写成9:9:9。后者感觉好难看、、、
<script type="text/javascript">
var attime;
function check(a){ //小于10的分钟和秒前面加个0
if(a<10){
a = "0" + a;
}
return a;
}
function clock(){
var time=new Date();
attime=time.getHours() + ":" + check(time.getMinutes()) + ":" + check(time.getSeconds());
document.getElementById("clock").value = attime;
}
setInterval(clock,1000);
</script>