早睡早起,方能养生
Sleep early rise early, way to keep healthy

JQuery电脑H5短信、邮箱验证码倒计时

super
2023-02-12 21:29
views 810

function sendMail() {
    if ($(".send-email-btn").hasClass("disabled")) {
        return false;
    }
    let email = $('#email').val();
    if (!email) {
        alert('请输入邮箱!');
        return false;
    }
    $.post("xx.php", {send_email:1,email}, function (data) {
        if (data == 1) {
            timeoutChangeStyle();
            alert('发送成功');
        } else {
            alert('发送失败');
        }
    });
}

var num = 60;

function timeoutChangeStyle() {
    $(".send-email-btn").addClass("disabled");
    if (num == 0) {
        $(".send-email-btn").text("重新发送");
        num = 30;
        $(".send-email-btn").removeClass("disabled");
    } else {
        var str = num + "s 后再次发送";
        $(".send-email-btn").text(str);
        setTimeout("timeoutChangeStyle()", 1000);
    }
    num--;
}


分享
0 条讨论
top