代码笔记 | 填写验证码倒计时60秒

来源:互联网 发布:新疆公路计价软件 编辑:程序博客网 时间:2024/06/06 08:41
 <input type="button" class="inpBtn" onclick="settime(this)" value="获取验证码" />          //点击验证码的方法            var countdown = 60;              function settime(obj) {                if (countdown == 59) {                    //发送验证码的主代码                  }                if (countdown == 0) {                    //点击后,过了60秒之后,恢复成获取验证码                    obj.removeAttribute("disabled")                    obj.style.backgroundColor="#44aaff";                    obj.value = "获取验证码";                    countdown = 60;                    return;                } else {                    //跳帧 0--->60                    obj.setAttribute("disabled", true);                    obj.style.backgroundColor="#ccc";                    obj.value = "重新发送(" + countdown + ")";                    countdown--;                }                setTimeout(function() {                    settime(obj)                }, 1000)            }    

0 0