1. 点击发送短信验证码
$("#sendSms").click(function(){
countdown(this);
var phone = $.trim($("#phoneNumber").val());
$.post("/phoneRegister",{phone: phone},
function(data, status){
if(data == "SUCCESS"){
/* alert("验证码已发送"); */
}else{
alert("发送失败,请重试");
}
});
});
- 按钮点击后禁用及倒计时60s
var timeWait = 60;
$("#sendSms").attr("disabled", false);
function countdown(o){
if(timeWait == 0){
o.removeAttribute("disabled");
o.innerHTML = "点击获取验证码";
timeWait = 60;
}else{
o.setAttribute("disabled", true);
o.innerHTML = timeWait + "秒后重新获取";
timeWait--;
setTimeout(function() {
countdown(o)
},1000)
}
}