jquery 倒计时发送短信验证码效果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shi851051279/article/details/53041809

话不多说直接上代码

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="js/jquery-1.12.3.min.js"></script>
    <script type="text/javascript">
        $(function () {

            $(".btn").click(function () {
                settime(this)
            });

            var countdown = 60;

            function settime(obj) {
                if (countdown == 0) {
                    obj.removeAttribute("disabled");
                    obj.innerHTML = "获取验证码";
                    countdown = 60;
                    return;
                } else {
                    obj.setAttribute("disabled", true);
                    obj.innerHTML = "" + countdown + "秒后再获取";
                    countdown--;
                }
                setTimeout(function () {
                    settime(obj)
                }, 1000)
            }
        });

    </script>
</head>
<body>

 <button class="btn">点击获取验证码</button>

</body>
</html>
阅读更多

没有更多推荐了,返回首页