jQuery实现倒计时点击发送短信验证码效果

做网站表单时候想要实现短信验证码点击发送后,倒计时60秒才可以重复点击发送按钮,应该如何实现呢?请看下面代码:

<!--引入jQuery库-->
<script src="/js/jquery.min.js"></script>

<script>
    var i=60;var t;
    $(function(){
        $("#button").click(function jishi(){
                $("#button").attr("value",i+"秒重发短信");
                i=i-1;
                $("#button").attr("disabled",true);
                t=setTimeout(jishi,1000);
                if(i==0){
                    clearTimeout(t);
                    $("#button").attr("disabled",false);
                    $("#button").attr("value","重新发送短信");  
                    i=60;               
                }
            });
    });
</script>

验证码:<input type="text" value=""/><input id="button"  type="button" value="发送短信"/>


通过上面代码就可以实现如下图效果了:

jQuery实现倒计时60秒效果

jQuery实现60秒重新发送验证码效果

如果内容有帮助,就点个赞吧!

转载注明出处:http://www.12564.cn/show-208.html

如有疑问请联系 QQ:644233191   微信:zw1688k