验证码倒计时60秒

<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>

 

posted @ 2018-12-06 14:18  时光博客  阅读(153)  评论(0编辑  收藏  举报