点击按钮,然后实现30S倒计时


点击按钮的之后,按钮进行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);}
   })

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM