var countdown=60;
function dx(val) {
if (countdown == 0) {
val.removeAttribute("disabled");
val.value="获取验证码";
countdown = 60;
} else if(countdown == 60){
$.modal.loading("正在获取验证码,请稍后...");
var phone = $.common.trim($("input[name='phone']").val());
$.ajax({
type: "post",
url: ctx + "dx",
data: {
"phone": phone
},
success: function(r) {
$.modal.closeLoading();
$.modal.msg(r.msg);
if(r.code==0){
val.setAttribute("disabled", true);
val.value="重新发送(" + countdown + ")";
countdown--;
setTimeout(function() {
dx(val)
},1000)
}
//
}
});
}else{
val.setAttribute("disabled", true);
val.value="重新发送(" + countdown + ")";
countdown--;
setTimeout(function() {
dx(val)
},1000)
}
}
<input type="button" id="btn" value="获取验证码" onclick="dx(this)" />
|