/*倒計時*/ var downTime = function (endTime,obj,callback){ /*基本判斷*/ if(!endTime || typeof endTime !== "string") return false; /*基本判斷*/ if(!obj || typeof obj !== "object") return false; /*獲取日期的毫秒*/ var endTime = Date.parse(endTime); /*定時器*/ setInterval(function () { var nowTime = +new Date(); /*2個時間的差 毫秒*/ var minus =endTime - nowTime; /*相差的天數*/ var day = parseInt(minus/1000/60/60/24); /*相差的小時*/ var hours = parseInt(minus/1000/60/60%24); /*相差的分鐘*/ var mintue = parseInt(minus/1000/60%60); /*獲取相差的秒*/ var second = parseInt(minus/1000%60); obj[0].innerHTML = parseInt(hours/10); obj[1].innerHTML = hours%10; obj[3].innerHTML = parseInt(mintue/10); obj[4].innerHTML = mintue%10; obj[6].innerHTML = parseInt(second/10); obj[7].innerHTML = second%10; },1000); callback && callback(); };