验证码60秒倒计时

 

验证码60秒倒计时(jQuery),

代码如下: 

                //验证码倒计时        
                var countdown = 60;
                var st;
                function settime(element) {
                    if (countdown != 0) {
                        st = setTimeout(function () {
                            settime(element);
                        }, 1000);
                    }
                    if (countdown == 0) {
                        element.removeAttr("disabled");
                        element.val("获取验证码");
                        element.removeAttr("style");
                        countdown = 60;
                        window.clearTimeout(st);
                    } else {
                        element.attr("disabled", true);
                        element.css({"background":"#CCC","color":"#fff"});
                        element.val("重新发送(" + countdown + ")");
                        countdown--;
                    }
                }

 

posted @ 2016-05-24 19:22  为师灭了你  阅读(441)  评论(0编辑  收藏  举报