天天看点

js/jquery倒计时发送验证码按钮

 <code>最近在写短信发送验证码,就写了个js倒计时发送验证码按钮</code>

js/jquery倒计时发送验证码按钮

&lt;script language="javascript" src="jquery-1.7.1.min.js"&gt;&lt;/script&gt;  

&lt;input type="button" id="btn" value="获取验证码"/&gt;  

&lt;script type="text/javascript"&gt;  

    var wait = resetwait = 60;  

    function timer(t) {  

        if (wait == 0) {  

            t.removeattribute("disabled");  

            t.value = "获取验证码";  

            wait = resetwait;  

        } else {  

            t.setattribute("disabled", true);  

            t.value = "重新发送(" + wait + ")";  

            wait--;  

            settimeout(function(){ timer(t) }, 1000);  

        }  

    }  

    $("#btn").click(function () {  

        timer(this);  

        sendsms(mobile, sendtype);  

    });  

    function sendsms(mobile, sendtype){  

        $.ajax({  

            type: 'post',  

            url: '/verify/index',  

            data: {mobile: mobile, type: sendtype},  

            success: function () {  

            }  

        });  

&lt;/script&gt;  

<code> </code>