倒计时

// 点击“获取验证码”
$("#getCode").click(function(){
if(!($("#getCode").hasClass("yes"))) {
var count=60; // 60s秒获取验证码
var phoneNum = $("#phoneN").val();
if(!phoneNum){
PopupCreate({
cont: "请输入移动号码!",
cueYes: "确定",
btYes: null,
sClass: "duihao",
hideNo: true
});
return;
}
if(phoneNum.length!=11){
PopupCreate({
cont: "请输入11位的移动号码",
cueYes: "确定",
btYes: null,
sClass: "duihao",
hideNo: true
});
return;
}
if(!(/^1(3[4-9]|5[012789]|8[23478]|47|78)d{8}$/.test(phoneNum))){
PopupCreate({
cont: "对不起,此次活动仅限移动用户参加!",
cueYes: "确定",
btYes: null,
sClass: "duihao",
hideNo: true
});
}else{
$("#getCode").addClass("yes");
$("#getCode").html(count+"秒后重发");
queryCode(phoneNum); // 请求手机验证码
countDown=window.setInterval(setTimer, 1000);
}

//定时器
function setTimer() {
var sendBt = $("#getCode");
sendBt.addClass("yes");
if (count == 1) {
window.clearInterval(countDown);
sendBt.removeAttr("disabled");
sendBt.removeClass("yes");
sendBt.html("获取验证码");
} else {
count--;
sendBt.html(count+"秒后重发");
}
}
}else{ return; }

});

原文地址:https://www.cnblogs.com/ey-151210/p/5772760.html