JavaScript定时器每隔60s发送一次短信
作者:互联网
1 <body> 2 手机号码:<input type="text"> 3 <button>发送</button>
<script> //获取button元素 let btn = document.querySelector("button"); //给button按钮添加click事件 btn.addEventListener("click", function () { btn.disabled = true;//按钮不可用 let time = 59;//倒计的时间 //创建定时器 let timer = setInterval(function () { if (time == 0) { //按钮可用 btn.disabled = false; //文字改变 btn.innerHTML = "发送"; //清除定时器效果 clearInterval(timer); } else { btn.innerHTML = "还剩" + time + "秒"; time--; } }, 1000);//每隔1s调用一次 }) </script>
标签:定时器,60s,button,JavaScript,按钮,let,time,btn 来源: https://www.cnblogs.com/sunho/p/16519245.html