发送验证码倒计时

使用方法:time($("input"))
/* 倒计时函数 */
var wait = 60,
    timer;
function time(o) {
    if(wait == 0) {
        o.removeAttr("disabled");
        o.css("backgroundColor", "rgba(34,211,162,1)");
        o.val("获取验证码");
        wait = 60;
    } else {
        o.attr("disabled", true);
        o.css("backgroundColor", "rgba(34,211,162,0.7)");
        o.val("重新获取(" + wait + "s)");
        wait--;
        timer = setTimeout(function() {
            time(o)
        }, 1000)
    }
}

你可能感兴趣的:(发送验证码倒计时)