簡(jiǎn)單的實(shí)現(xiàn)頁(yè)面倒計(jì)時(shí)js
<script>
function ShowCountDown(year,month,day,hour,minute,second) {
var now = new Date();
var endDate = new Date(year,month-1,day,hour,minute,second);
var leftTime = endDate.getTime() - now.getTime();
var dd = parseInt(leftTime / 1000 / 60 / 60 / 24, 10);//計(jì)算剩余的天數(shù)
var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10);//計(jì)算剩余的小時(shí)數(shù)
var mm = parseInt(leftTime / 1000 / 60 % 60, 10);//計(jì)算剩余的分鐘數(shù)
var ss = parseInt(leftTime / 1000 % 60, 10);//計(jì)算剩余的秒數(shù)
dd = checkTime(dd);
hh = checkTime(hh);
mm = checkTime(mm);
ss = checkTime(ss);
document.getElementById("s_day").innerHTML = dd;
document.getElementById("s_time").innerHTML = hh;
document.getElementById("s_minute").innerHTML = mm;
document.getElementById("s_second").innerHTML = ss;
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
window.setInterval(function () { ShowCountDown(2017,10,10,00,00,00); }, 1000);
</script>