首页 > 代码库 > 倒计时方法

倒计时方法

function countdown (id, seconds){
    var elem = document.getElementById(id);
    var iniseconds = numseconds = parseInt(seconds) || 60;
    var downtime;
    var callback = function (num){
        var numhtml = "<i>"+ num +"</i> 重新发送";
        elem.setAttribute("disabled", "disabled");
        elem.innerHTML = numhtml;
        if (num <= 0){
            elem.removeAttribute("disabled");
            elem.innerHTML = "重新发送";
        }
    }
    var doTiming = function (){
        callback(numseconds);
        if (numseconds <= 0){
            clearTimeout(downtime);
            return;
        }
        numseconds--;
        downtime = setTimeout(arguments.callee, 1000);
    }();
}

 

从来就没有想起,永远也不会忘记