实现发送短信验证码后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);
                }
            })

        });

 

posted @ 2017-03-07 10:02  shiningrise  阅读(801)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css