表单按钮倒计时 》验证码 jQuery&&JavaScript

来源:互联网 发布:全国所有中小学数据库 编辑:程序博客网 时间:2024/06/06 03:54

<script src="jquery-2.1.4.min.js"></script>

<input type="button" id="btn" value="免费获取验证码" />

//jquery代码

<script type="text/javascript">

//jquery代码

    $(document).ready(function(){
        $("#btn").click(function(){
            time(this)
        })
        var wait=60;
        function time(o) {
            if (wait == 0) {
                o.removeAttribute("disabled");
                o.value="免费获取验证码";
                wait = 60;
            } else {
                o.setAttribute("disabled", true);
                o.value="重新发送(" + wait + ")";
                wait--;
                setTimeout(function() {
                        time(o)
                    },
                    1000)
            }
        }
    })
    
////////////////////////////////////////////////////////////////////////////////////////////
    //js原生
//    document.getElementById("btn").onclick=function(){
//        time(this);
//    }
//    var wait=60;
//    function time(o) {
//        if (wait == 0) {
//            o.removeAttribute("disabled");
//            o.value="免费获取验证码";
//            wait = 60;
//        } else {
//            o.setAttribute("disabled", true);
//            o.value="重新发送(" + wait + ")";
//            wait--;
//            setTimeout(function() {
//                    time(o)
//                },
//                1000)
//        }
//    }
    
</script>
1 0