JavaScript获取短信验证码(周期性)
ITzhongzi 人气:0本文实例为大家分享了js周期性获取短信验证码的具体代码,供大家参考,具体内容如下
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <input type="text"/> <input type="button" id="btn" value="点击发送验证码"/> <script> 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); }; </script> </body> </html>
加载全部内容