js 短信60秒倒計時
阿新 • • 發佈:2018-09-22
思想 按鈕 out -- 驗證 code style 定義 font
廢話不多說,看代碼。
這是獲取短信的按鈕
<a href="javascript:void(0);" id="gSMS" onclick="get_sms_captcha(‘2‘)" style="font-size: 0.6rem;color: #444;left: 0.5rem;">獲取短信驗證碼</a>
下面是js代碼,思想就是定義60的數,然後定時器設置為一秒,每一秒執行一次。等到0是就可以重新獲取短信驗證碼。
var countDownT = 60; function get_sms_captcha(type){ countDownT = 60; setTime(); //下方寫業務 } function setTime(){ if (countDownT == 0){ $("#gSMS").attr("onclick","get_sms_captcha(‘2‘)"); $("#gSMS").text("獲取短信驗證碼"); } else{ $("#gSMS").attr("onclick","#"); $("#gSMS").text("重新發送("+countDownT+")"); countDownT--; setTimeout(function () { setTime(); },1000) } }
js 短信60秒倒計時