jQuery 实现按钮点击后倒计时 如短信验证码发送等

时间:2021-08-25 18:11:47   收藏:0   阅读:31

1.前端页面给一个按钮
<button type="button" class="btn-xlarge" id="dyMobileButton">发送验证</button>
2.jQuery如下
<script>
   //给按钮一个点击事件
   $(‘#dyMobileButton‘).click(function () {
     //设置时常,以秒计算
       var time=60;
    var timer = setInterval(function () {
       time--;
       if (time > 0){
         //正在倒计时
         $(‘#dyMobileButton‘).html(‘重新发送‘ + time + ‘秒‘);
         $(‘#dyMobileButton‘).prop(‘disabled‘,true);
       }else{
         $(‘#dyMobileButton‘).html(‘发送验证码‘);
         $(‘#dyMobileButton‘).prop(‘disabled‘,false);
         clearInterval(timer);
       }
     },1000)
   })
</script>

原文:https://www.cnblogs.com/ylf2000/p/15184997.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!