效果如图点击时候 倒计时 结束 之后可以发送


jquery,js php 发送短信验证吗 前端 点击事件时间倒计时


代码如下


我按顺序 写  看下 html 点击发送的那个按钮

jquery,js php 发送短信验证吗 前端 点击事件时间倒计时


1.点击事件触发

$("#mobile_code").click(function(){

   var contacts_phone=123456465;

   send_mobile_code(contacts_phone, $(this));

})

调用    send_mobile_code  方法

2.方法 如下

function send_mobile_code(mobileCodeObj, sendButton) {
   countdown(sendButton); //调用按钮 让它倒计时 显示
   console.log('发送了');
   return  false;
   var url = 'apply.php';
   $.post(url, {
      act: 'send_mobile_code',
      mobile_code:mobileCodeObj,
   }, function(result) {
      if (result == 'ok') {
         //倒计时
         countdown(sendButton);
      } else {
         alert(result);
      }
   }, 'text');
}

3. countdown 方法 如下 


function countdown(obj, msg) {


   if (wait == 0) {
      obj.removeAttr("disabled");
      obj.html(msg);
      wait = 60;
   } else {
      if (msg == undefined || msg == null) {
         msg = obj.html();
      }
      obj.attr("disabled", "disabled");
      obj.html(wait + "秒后重新获取");
      wait--;
      setTimeout(function() {
         countdown(obj, msg)
      }, 1000)
   }
}
这里面有个坑 就是 obj.html这个

jquery,js php 发送短信验证吗 前端 点击事件时间倒计时

我这个标签 是a  标签所以用的  html  要是 input的  要用 val 


相关文章:

  • 2022-01-30
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2021-07-09
  • 2021-12-04
  • 2022-12-23
猜你喜欢
  • 2021-11-25
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案