天天看點

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>