• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
丶菜鸟也会飞
博客园    首页    新随笔    联系   管理    订阅  订阅
10s后再次获取手机验证码

一般手机验证码获取都会加个间隔时间

js代码如下:

function getDxCode(btn){
var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
var mobilenum = document.getElementById("shoujih").value;
var flag = reg.test(mobilenum); //true
if(!flag){alert("请输入正确的手机号码"); return;}
//alert(mobilenum);
$.ajax({
type:"post",
url:"<%=request.getContextPath() %>/admin/ywtw/send_dx_code.jsp",
dataType:"text",
data:{"mobilenum":mobilenum},
success: function(json){
alert('send success');
}
});
time(btn);
}
//等待时间(测试时间为10秒)
var wait = 120;
function time(btn) {
if (wait == 0) {
btn.removeAttribute("disabled");
btn.innerHTML = "获取";
wait = 120;
} else {
btn.setAttribute("disabled", true);
btn.innerHTML = wait + "秒后重新获取";
wait--;
setTimeout(function () {
time(btn);
},1000)
}
}

html代码如下:

//οnclick="sendCode(this),传入按钮自身对象this

<div class="tabCon_a">
<input type="text" class="shoujih" name="shoujih" id="shoujih" value="" placeholder="手机号"/><br />
<div class="getsjyzm"><input type="text" name="dxcode" class="passW" id="dxcode" value="" placeholder="手机验证码"/>

<span class="getYzm" onClick="getDxCode(this);" style="width:110px">获取</span></div>
</div>

 

参考原博:

https://blog.csdn.net/X_0101/article/details/108224395

posted on 2021-03-01 16:48  丶菜鸟也要飞  阅读(241)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3