发送验证码倒计时效果

效果图:

代码:

 $(function() {
            var Time = 10,
                t;
            var c = Time
            $("#fsyzm").on("click", function() {
                console.log("开始了");
                timedCount();
            })

            function timedCount() {
                $('#fsyzm').val("请稍等(" + c + ")");
                $('#fsyzm').attr("disabled", "disabled");
                c = c - 1;
                t = setTimeout(function() {
                    timedCount();
                }, 1000);
                if (c < 0) {
                    c = Time;
                    stopCount();
                    $('#fsyzm').val("发送校验码");
                    $('#fsyzm').removeAttr("disabled");

                }
            }

            function stopCount() {
                clearTimeout(t);
            }
        })

 升级版本 防止刷新

 

posted @ 2017-06-26 13:42  h5monkey  阅读(1294)  评论(0编辑  收藏  举报