jquery发送短信按钮倒计时

<html>
 <head></head>
 <body>
  <div class="position-relative LoginBox"> 
   <div class="LoginIcon display-flex justify-content align-center"> 
    <img src="/static/index/img/login1.png" /> 
   </div> 
   <input class="Login-input" type="text" name="rphone" placeholder="手机号" /> 
  </div> 
  <div class="position-relative LoginBox"> 
   <div class="LoginIcon display-flex justify-content align-center"> 
    <img src="/static/index/img/login4.png" /> 
   </div> 
   <input class="Login-input LoginTest" type="text" name="rsms_code" placeholder="短信验证码" /> 
   <div class="LoginImg display-flex justify-content align-center"> 
    <button class="getCodeBtn" onclick="sendSms($(this))" id="yanzhengma">获取验证码</button> 
   </div> 
  </div> 
  <div class="position-relative LoginBox"> 
   <div class="LoginIcon display-flex justify-content align-center"> 
    <img src="/static/index/img/login3.png" /> 
   </div> 
   <input class="Login-input LoginTest" type="text" name="rcode" placeholder="请输入验证码" /> 
   <div class="LoginImg display-flex justify-content align-center"> 
    <img src="{:captcha_src()}" alt="captcha" id="captcha" onclick="this.src=this.src+'?'+Math.random()" /> 
   </div> 
  </div>
 </body>
</html>

function sendSms(obj)
	{
		obj[0].disabled = true;
		var formData = new FormData();
		formData.append("phone",$("input[name='rphone']").val())
		formData.append("code",$("input[name='rcode']").val())
		if(formData.get("phone") == "") {
			Tpop("提示","请输入手机号");return;
		}
		if(formData.get("code") == "") {
			Tpop("提示","请输入验证码");return;
		}
		$.ajax({
			url: "/api/Login/sendVeri",
			method:'POST',
			data: formData,
			processData:false,
			contentType: false,
			dataType:'json',
			success:function(res){
				if (res.code == 200) {
					var time = 60;
					var timeclose = setInterval(function(){
						obj[0].innerHTML = time+"秒后重新获取";
						time--;
						if (time <= 0) {
							clearInterval(timeclose);
							obj[0].disabled = false;
							obj[0].innerHTML = "重新获取";
						}
					},1000);
					Tpop("提示",res.msg);return;
				} else {
					obj[0].disabled = false;
					Tpop("提示",res.msg);
					$('#captcha').click();
					return;
				}
			}});
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值