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

点击按钮的以后,按钮进行30S倒计时this

HTMLspa

<input type="button" id="getCode" name="" value="获取验证码" class="btnCode"/>

CSScode

.btnCode {
    width: 40%;
    height: 42px; 
    background: #FFF; 
    color: #323333;
    font-size: 14px;
    line-height: 42px; 
}

.btnCodeDisabled {
    background: #ccc; 
}

JSblog

$(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);}
   })
相关文章
相关标签/搜索