1. 程式人生 > >js 發送短信驗證碼倒計時

js 發送短信驗證碼倒計時

set attribute urn 發送 eat isa ttr move 計時

html

<input type="button" id="btn" value="免費獲取驗證碼" onclick="settime(this)" />

js

// 短信驗證碼倒計時
var countdown=60;
function settime(obj) {
if (countdown == 0) {
obj.removeAttribute("disabled");
obj.value="免費獲取驗證碼";
countdown = 60;
return;
} else {
obj.setAttribute("disabled", true);
obj.value="重新發送(" + countdown + ")";
countdown--;
}
setTimeout(function() {
settime(obj) }
,1000)
}



js 發送短信驗證碼倒計時