实现发送短信验证码后60秒倒计时

实现发送短信验证码后60秒倒计时

https://www.oschina.net/code/snippet_2001568_48247

 var countdown = 0;
        function settime(obj) {
            if (countdown == 0) {
                obj.removeAttribute("disabled");
                obj.text = "免费获取验证码";
                //countdown = 60;
                return;
            } else {
                obj.setAttribute("disabled", true);
                obj.text = "重新发送(" + countdown + ")";
                countdown--;
            }
            setTimeout(function () {
                    settime(obj);
                },
                1000);
        }

        $("#getcode").click(function () {
            if (CheckInput() == false) {
                return;
            }
            if (countdown == 0) {
                countdown = 60;
                settime(this);
            } else {
                return;
            }
                
            _ajax("@Url.Action("GetVerificationCode","User")", {
                e_mobile: $("#e_mobile").val()
            }, function (json) {
                alert(json.msg);
                if (json.flag > 0) {
                    cacheKey = json.cacheKey;
                    console.log(cacheKey);
                }
            })

        });
原文地址:https://www.cnblogs.com/shiningrise/p/6513221.html