jquery短信验证码倒计时效果

1. 点击发送短信验证码

    $("#sendSms").click(function(){
        countdown(this);
        var phone = $.trim($("#phoneNumber").val());
        $.post("/phoneRegister",{phone: phone},
            function(data, status){
                if(data == "SUCCESS"){
                    /* alert("验证码已发送"); */
                }else{
                    alert("发送失败,请重试");
                }
        });
    });
  1. 按钮点击后禁用及倒计时60s
    var timeWait = 60;
    $("#sendSms").attr("disabled", false);
    function countdown(o){
        if(timeWait == 0){
            o.removeAttribute("disabled");
            o.innerHTML = "点击获取验证码";
            timeWait = 60;
        }else{
            o.setAttribute("disabled", true);
            o.innerHTML = timeWait + "秒后重新获取"; 
            timeWait--;
            setTimeout(function() {
                countdown(o)
            },1000)
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容