首页 > 技术文章 > js 发送验证码倒计时

ldj3 2018-06-27 14:44 原文

首先写一个按钮:

<input type="button" id="btn" value="免费获取验证码" onclick="time(this)" />

然后写js代码:

var wait=60;
    function time(o){
        if (wait==0) {
            o.innerHTML="重新发送验证码";
            o.style.backgroundColor="#388BE8";
            o.removeAttribute("disabled");
            wait=60;
        }else{
            o.setAttribute("disabled", true);
            o.innerHTML=wait+"秒后重新获取";
            o.style.backgroundColor="#8f8b8b";
            wait--;
            setTimeout(function(){
                time(o)
            },1000)
        }
        
    }

欢迎关注微信公众号:lovephp

推荐阅读