你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

thinkphp6短信验证码60秒发送

2021/12/20 12:01:39
表单:
<input type="text" id="code" name="code" placeholder="验证码" class="input-xfat input-xlarge" style="width:120px">
<button type="button" class="btn-xlarge" id="dyMobileButton">发送验证码</button>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
$('#dyMobileButton').click(function (){
   var tel=$('#phone').val();
   var time=60;
   // 设置定时器
   var timer=setInterval(function (){
      time--;
      if(time>0){
         // 正在倒计时
         $('#dyMobileButton').html('重新发送:'+time+'秒');
         $('#dyMobileButton').prop('disable',true);
      }else{
         // 停止倒计时
         $('#dyMobileButton').html('发送验证码');
         $('#dyMobileButton').prop('disable',false);
         clearInterval(timer);
      }
   },1000)
   $.ajax({
      url:"getPhone",
      data:{tel:tel},
      type:'get',
      dataType:'json',
      success:function(e){
         console.log(e);
      }});
})