用 js 来实现网页显示倒计时效果
1 function checkTime( time ){ 2 var data = new Data(); // 获取现在时间 3 var nowData = data.getTime(); // 转化成毫秒数 4 var time ; // 结束的时间 5 var t = time - nowData ; 6 var HH, mm , ss = 0; 7 var sta = ""; 8 if( HH == 24){ 9 HH = 0; 10 } 11 if( ++ss == 60){ 12 if( ++mm == 60 ){ 13 HH++; 14 mm = 0; 15 } 16 ss = 0; 17 } 18
// 11-17行的简写
if (++ss == 60) {
if (++mm == 60) { HH++; mm = 0; }
ss = 0;
}
19 if( t > 0){ 20 HH = Math.floor(t/1000/60/60%24); 21 mm = Math.floor(t/1000/60%60); 22 ss = Math.floor(t/1000%60); 23 str += HH < 10 ? "0" + HH : HH; 24 str += ":"; 25 str += mm < 10 ? "0" + mm : mm; 26 str += ":"; 27 str += ss < 10 ? "0" + ss : ss; 28 $(".progress-time span").text(str); 29 } 30 }
setInterval(function () { // 每隔一秒调用一次
checkTime(time)
},1000);
显示效果: