手机验证码倒计时(防重复点击) 发表于 2016-10-14 获取手机验证码的倒计时 封装函数获取手机验证码的倒计时12345678910111213141516171819<input type="button" value="获取验证码" id="btn1">window.onload = function(){ var wait=60; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value="获取验证码"; wait = 60; } else { o.setAttribute("disabled", true); o.value="重新发送(" + wait + ")"; wait--; setTimeout(function(){ time(o) },1000); } } document.getElementById("btn").onclick=function(){time(this);}}; 封装函数(jQuery)获取手机验证码的倒计时12345678910111213141516171819202122<input type="button" value="获取验证码" id="btn1">$(function(){ var wait=5; function time(el){console.log(wait); if(wait==0){ el.removeAttr('disabled'); el.val('重新获取'); wait=5; }else{ el.attr('disabled',true); el.val('稍等片刻('+ wait +')'); wait--; setTimeout(function(){ time(el); },1000); } } $('#btn1').on('click',function(){ var self=$(this); time(self); });}); 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏 支付宝打赏