我想到了倒计时时候的一段代码,求助!
既然setTimeout是只执行一次,这里也没发现有循环的语句,他是怎么做到无限循环的
window.onload = function(){
showtime()
}
function check(i){
if(i<10){
i = "0" +i;
}
return i;
}
function showtime(){
var curtime = new Date();
var endtime = new Date("2016/3/22,11:45:30");//?个重要
var lefttime = parseInt((endtime.getTime()-curtime.getTime())/1000)
var day = parseInt((lefttime)/(24*60*60));//Math不能漏
var date = parseInt(lefttime/(60*60)%24);
var mins = parseInt(lefttime/60%60);
var ss = parseInt(lefttime%60)
date = check(date);
mins = check(mins);
ss = check(ss);
document.getElementById("time").innerHTML = "距房子到期有 " + day + "天-" + date + ":" + mins +":" + ss+"";
if(lefttime<=0){
document.getElementById("time").innerHTML = "房子已到期"
}
var t = setTimeout(showtime,300);
}