首页 资讯 社群 我的社区 搜索

jQuery 短信验证码倒计时

yimo~
2020-05-11 11:54:46
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<button id="btn-vcode" class="btn-vcode sigin_btn form_btn" type="button" style="border:none;">点击获取验证码</button>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
    $(function(){
        time($("#btn-vcode"));
    });
 
    var wait = 60;
    function time(o) {
        if (wait == 0) {
            o.removeAttr("disabled");
            o.html('验证码');
            wait = 60;
        } else {
            o.attr("disabled", "disabled");
            o.html(wait + "秒");
            wait--;
            setTimeout(function () {
                        time(o);
                    },
                    1000);
        }
    }
</script>
</body>
</html>
用户评论