标签:
1 var Btn = document.getElementById(‘btn‘); 2 var star = 10; 3 4 Btn.onclick = function(){ 5 var timer = setInterval(function(){ 6 star--; 7 Btn.disabled = true; 8 Btn.innerHTML = "重新发送验证码" + "(" + star + ")"; 9 console.log(star); 10 if(star <= 0){ 11 Btn.innerHTML = "获取短信验证码"; 12 Btn.disabled = false; 13 clearInterval(timer); 14 } 15 }, 1000); 16 }
html:
<button type="button" id="btn">获取短信验证码</button>
值得一提的是,button按钮的类型问题,button按钮的默认类型是submit类型,如果不指定具体的的button类型的话,就会默认为submit,这样点击时候就会刷新页面,导致效果重置
标签:
原文地址:http://www.cnblogs.com/hello107/p/5814629.html