我有一個倒計時jquery小時,分鐘和秒工作。到目前爲止,這完美運作。不過,我希望它也jquery倒計時一天
日這算的是JS FIDDLE
HTML
<div id="counttime">24:00:00</div>
<div id="cons"></div>
JQUERY
function pad(num) {
return num<10?"0"+num:num;
}
$(function() {
var tCont = $('#counttime');
var timer = tCont.html().split(':');
if (timer.length === 2) timer.unshift(0);
var endMilli= timer[0]*60*60*1000;
endMilli += timer[1]*60*1000
endMilli += timer[2]*1000;
if(endMilli > 0) {
var endTime = new Date(Date.now()+endMilli);
$("#cons").append("<br>"+endTime);
var tId = setInterval(function() {
var diff = endTime.getTime()-Date.now();
if (diff<=0) {
tCont.html("00:00:00");
clearInterval(tId);
}
else {
var d = new Date(diff);
hh = pad(d.getUTCHours());
mm = pad(d.getMinutes());
ss = pad(d.getSeconds());
tCont.html(""+hh+":"+mm+":"+ss);
}
},300);
}
});
對不起......您今天的意思是什麼? – 2014-12-03 04:05:47
你的問題並不完全清楚。不要說「它工作正常」,你可以請努力描述什麼是「它工作正常」的行爲 – Leo 2014-12-03 04:09:22
@ArunPJohny的意思是我想要倒數日,小時,分鐘,秒......現在只有小時,分鐘,第二個 – TheSmile 2014-12-03 04:20:07