博客园  :: 首页  :: 新随笔  :: 订阅 订阅  :: 管理

1111

Posted on 2016-07-07 22:42  jason-xiao  阅读(80)  评论(0编辑  收藏  举报
    <script src="js/zepto.min.js"></script>
    <script>
        $(function () {
            $("#getCode").on("click", function () {
                fn_sendSMS();
            });

            function fn_sendSMS()
            {
                $("#getCode").text("5秒后重新发送").addClass("disabled").off("click");
                intervalId = setInterval(function () {
                    var target = $("#getCode");
                    var num = /^\d{1,2}/.exec(target.text());
                    var currentSecond = parseInt(num[0]);
                    if (currentSecond == 1) {
                        target.text("重新发送").removeClass("disabled").on({ "click": fn_sendSMS });
                        clearInterval(intervalId);
                    } else {
                        target.text((--currentSecond) + "秒后重新发送");
                    }
                }, 1000);
            }
        });
    </script>