倒计时代码
//倒计时
var time = 36500;//总时间
function timeDown(){
var timer = setInterval(function(){
time--;
//判断时间为0时关闭定时器
if(time = 0){
clearInterval(timer);
}
//获取显示的元素
var spans = document.querySelectorAll('span');
var hour = twoDouble(Math.floor(time%86400/3600));
var minute = twoDouble(Math.floor(time%86400%3600/60));
var seconds = twoDouble(Math.floor(time%60));
//展示时间
spans[0].innerHTML = Math.floor(hour/10);
spans[1].innerHTML = hour%10;
spans[2].innerHTML = Math.floor(minute/10);
spans[3].innerHTML = minute%10;
spans[4].innerHTML = Math.floor(seconds/10);
spans[5].innerHTML = seconds%10;
},1000)
}
//将数字转为2位数字
function twoDouble(num){
return num<10? "0"+num : ""+num ;
}