验证码倒计时

来源:互联网 发布:福昕阅读器有mac版吗 编辑:程序博客网 时间:2024/06/05 02:13
<input id="mobile" placeholder="请输入验证码" maxlength="6">
<input type="button" id="btn" value="免费获取验证码" />
<script type="text/javascript">
    var wait = 30;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.value = "免费获取验证码";
            wait = 30;
        } else {

            o.setAttribute("disabled", true);
            o.value = "重新发送(" + wait + ")";
            wait--;
            setTimeout(function() {
                time(o)
            }, 1000)
        }
    }
    //document.getElementById("btn").onclick=function(){time(this);}

    $("#btn").on('click', function() {
        var mobile = $("#mobile").val();
        if (mobile == null || mobile == '') {
            alert("验证码不能为空")
        } else {
            time(this);
            
        }
    })
0 0
原创粉丝点击