简单的js倒计时函数

需要引入jQuery

/
* 倒计时
*@param el
*@param time
*/
function smsTimeOut(el, time) {
    var time = time || 60;
    window.localTimer = setTimeout(function () {
        smsTimeOut(el, time);
    }, 1000);

    if (window.localTime == undefined) window.localTime = time;

    if (window.localTime > 0) {
        $(el).prop('disabled', true).html(window.localTime + '秒后获取')
        window.localTime--;
    } else {
        clearTimeout(window.localTimer);
        window.localTime = time;
        $(el).prop('disabled', false).html(' 获取验证码');
    }
}

标签: 无

评论已关闭