简单的实现页面倒计时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);//计算剩余的天数
var hh = parseInt(leftTime / 1000 / 60 / 60 % 24, 10);//计算剩余的小时数
var mm = parseInt(leftTime / 1000 / 60 % 60, 10);//计算剩余的分钟数
var ss = parseInt(leftTime / 1000 % 60, 10);//计算剩余的秒数
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>
网友评论