window.onload=function(){
function smove(){
var now=new Date();
var end=new Date("2017,8,3");
var LeftTime=document.getElementById("LeftTime");
var time=end.getTime()-now.getTime();
var d=parseInt(time/(1000*60*60*24));
var h=parseInt(time/(1000*60*60))-(d*24);
var m=parseInt(time/(1000*60))-(d*24*60)-(h*60)
var s=parseInt(time/(1000))-(d*24*60*60)-(h*60*60)-(m*60);
LeftTime.innerHTML=d+"天"+h+"小时"+m+"分钟"+s+"秒";
}
setInterval(smove(),500);
}
这样为何不能实时刷新,只能手动刷新才能看见时间在缩短。难道是setinterval()
获取不了smove()的元素?还是
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -分割线
window.onload=function(){
setInterval(function(){
var now=new Date();
var end=new Date("2017,8,3");
var LeftTime=document.getElementById("LeftTime");
var time=end.getTime()-now.getTime();
var d=parseInt(time/(1000*60*60*24));
var h=parseInt(time/(1000*60*60))-(d*24);
var m=parseInt(time/(1000*60))-(d*24*60)-(h*60)
var s=parseInt(time/(1000))-(d*24*60*60)-(h*60*60)-(m*60);
LeftTime.innerHTML=d+"天"+h+"小时"+m+"分钟"+s+"秒";
},500);
}
这样写确可以