JavaScript 发送短信案例

    xiaoxiao2021-03-25  171

    通过javascript 实现 发送短信验证码的案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="text"> <button id="btn">点击发送短信</button> </body> </html> <script> var btn = document.getElementById("btn") var count = 3; var timer = null; btn.onclick = function() { this.disabled = true; //this是指向btn的 var that = this;//把btn对象给that timer = setInterval(sendTextMessage,1000); function sendTextMessage() { count--; if(count >= 0){ that.innerHTML = "还剩余"+count+"秒"; } else { that.innerHTML = "重新发送"; that.disabled = false; clearInterval(timer); //清除定时器 count = 5 ; } } } </script>
    转载请注明原文地址: https://ju.6miu.com/read-5524.html

    最新回复(0)