<code>最近在寫短信發送驗證碼,就寫了個js倒計時發送驗證碼按鈕</code>

<script language="javascript" src="jquery-1.7.1.min.js"></script>
<input type="button" id="btn" value="擷取驗證碼"/>
<script type="text/javascript">
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 () {
}
});
</script>
<code> </code>