点击获取验证码进行60秒倒计时

$('.getCode').on('click', function() {
            var self = $(this);
            countdown(self);
        });
        var countdownNum = 60;

        // 倒计时
        function countdown(obj) {
            if(countdownNum == 0) {
                obj.attr('disabled', false); 
                obj.val('获取验证码');
                countdownNum = 60;
                return;
            } else {
                obj.attr('disabled', true);
                obj.val(countdownNum + '秒后重新发送');
                countdownNum--;
            }

            setTimeout(function () {
                countdown(obj);
            }, 1000);  
        }

 

posted @ 2018-04-09 19:03  段伏英  阅读(1064)  评论(0编辑  收藏  举报