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

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




代码如下


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



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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值