标签:
点击按钮的之后,按钮进行30S倒计时
HTML
<input type="button" id="getCode" name="" value="获取验证码" class="btnCode"/>
CSS
.btnCode { width: 40%; height: 42px; background: #FFF; color: #323333; font-size: 14px; line-height: 42px; } .btnCodeDisabled { background: #ccc; }
JS
$(function(){ var wait=30; function time(obj) { if (wait == 0) { obj.className=‘btnCode‘; obj.removeAttribute("disabled"); obj.value=""; //wait = 30; } else { obj.className=‘btnCodeDisabled‘;//按钮变灰,不可点击 obj.setAttribute("disabled", true); obj.value="重新发送("+ wait +")"; wait--; setTimeout(function() { time(obj) }, 1000) } } document.getElementById("getCode").onclick=function(){time(this);} })
标签:
原文地址:http://www.cnblogs.com/yaowangmx/p/5413212.html