javascript实现5秒倒计时重新发送短信功能
js实现5秒倒计时重新发送短信功能,具有一定的参考价值。
html:
<div class="box"> <input type="text" name="" id="txt"> <button type="button" id="btn">点击发送短信</button> </div>
js:
<script type="text/javascript"> window.onload = function(){ function $(id){ return document.getElementById(id); } // 点击按钮的时候 $('btn').onclick = function(){ // 清除定时器 clearInterval(timer); var _self = this; // 让按钮,处于禁用状态,设置其disabled为true _self.disabled = true; var count = 5; var timer = setInterval(function(){ if(count>0){ count--; _self.innerHTML = '剩余时间' + count + 's'; }else{ _self.innerHTML = '重新发送短信'; _self.disabled = false; // 清除定时器 clearInterval(timer); } },1000); } } </script>
