//html
<em id="countDown"></em>
//js
<script>
var countDown={
obj:document.getElementById('countDown'),
timer:null,
leftTime:8006,
//将0-9的数字前面加上0,例1变为01
checkTime:function(i) {
return i<10?('0'+i):i;
},
setTime:function(){
var that=this;
that.timer=setInterval(function(){
if(that.leftTime<=0){
that.leftTime = 3601;
}
that.leftTime--;
var hours = that.checkTime(parseInt(that.leftTime / 60 / 60)); //计算剩余的小时
var minutes = that.checkTime(parseInt(that.leftTime / 60 % 60));//计算剩余的分钟
var seconds = that.checkTime(parseInt(that.leftTime % 60));//计算剩余的秒数
that.obj.innerHTML=hours+":"+minutes+":"+seconds;
},1000)
}
}
countDown.setTime();
</script>
网友评论