验证码倒计时60秒

时间:2022-08-14 22:07:20
<script src="../../public/jquery.js"></script>
<h4>验证码</h4>
<div class="regin_yan_bac">
   <input type="password">
   <button class="sms_click">发送验证码</button>
</div>

<script>
   //获取验证码
   var wait = 60;
   function countdown(timeer) {
     var $timeer = $(timeer)
     if (wait == 0) {
       $timeer.attr("disabled", false);
       $timeer.html("发送验证码")
       wait = 60;
     } else {
       $timeer.attr("disabled", true);
       $timeer.html(+wait + "秒后获取");
       wait--;
       setTimeout(function () {
          countdown(timeer)
       }, 1000);
   }
}

$(".sms_click").on("click", function () {
   countdown(this);
})
</script>