var attime;
function clock(){
var time=new Date();
var h = time.getHours();
var m = time.getMinutes();
var s = time.getSeconds();
checkTime(m);
checkTime(s);
attime= h+':'+m+':'+s ;
document.getElementById("clock").value = attime;
function checkTime(k){
if(k<10){
k='0'+k;
}
return k;
}
}
var timer = setInterval(clock,1000)
为什么秒针小于10的情况下不会添0
你赋值才会改变
checkTime(m); ----> m = checkTime(m);
checkTime(s); -----> s = checkTime(s);
你在函数里返还一个数要赋值给会原来的,原来的才会改变