本文实例为大家分享了js周期性获取短信验证码的具体代码,供大家参考,具体内容如下
Meta charset="UTF-8">
var timerId = null;
var btn = document.getElementById("btn");
var num = 5;
btn.onclick = function () {
btn.disabled = true;
timerId = setInterval(function () {
num--;
btn.value = num + "秒后可以发送";
if (num === 0) {
clearInterval(timerId);
btn.value = "点击发送验证码";
btn.disabled = false;
num = 5;
}
},1000);
};