jquery 24小時倒計時

<span>倒計時:&nbsp;</span><span id="timer"></span>
        


var oBox= document.getElementById('timer');       
var maxtime = 24*60 * 60;  
function CountDown() {
    if (maxtime >= 0) {
        hour=  Math.floor(maxtime / 3600);
        minutes = Math.floor(maxtime  / 60 % 60);
        seconds = Math.floor(maxtime  % 60);
        msg = checkTime(hour) + ":" + checkTime(minutes) + ":" + checkTime(seconds);
        oBox.innerHTML = msg;
        if (maxtime == 5 * 60)alert("還剩5分鐘");
                    --maxtime;
        } else{
                clearInterval(timer);
                alert("時間到,結束!");
                // this.left = false;
                // this.right= false;
                // this.midBottom = false;
            }
        }
timer = setInterval("CountDown()", 1000);
function checkTime(i) { //將0-9的數字前面加上0,例1變爲01 
     if(i < 10) {
        i = "0" + i;
     }
     return i;
}
window.onload = CountDown;  //jquery當即執行倒計時的函數
複製代碼
相關文章
相關標籤/搜索