var wait=60;
function reSendCode(id) {
var obj = $("#"+id);
if (wait == 0) {
obj.attr("disabled",false);
$(‘#getcode‘).removeClass(‘no-disable‘).addClass("get-code").attr(‘disabled‘,false).val("免费获取验证码");
wait = 60;
} else {
$(‘#getcode‘).removeClass(‘get-code‘).addClass("no-disable").attr(‘disabled‘,true).val( wait +"秒后点击重新发送");
wait--;
setTimeout(function() {
reSendCode(id)
},
1000)
}
}
<input type="button" id="getcode" class="get-code" value="获取短信验证码" >
$("#getcode").click(function(){
var tel = $("#mobiletel").val();
if(tel==‘‘){
alert("请先输入手机号码");
return false;
}
var partten = /^(0|86|17951)?(13[0-9]|15[012356789]|18[0-9]|14[57])[0-9]{8}$/;
if (tel.length != 11 || !partten.test(tel)) {
alert("手机号码不正确,请您重新输入");
return false
}
var ajax_url = $(this).attr("ajaxurl");
var post_data = "mobile="+tel+"&m="+Math.random();
$.ajax({
type: "POST",
url: ajax_url,
data: post_data,
dataType: "json",
success: function (json_obj) {
var dataObj=json_obj;
reSendCode(‘getcode‘);
if(dataObj.status=="7"){
alert(dataObj.msg);
window.location.href = dataObj.forward;
}else{
alert(dataObj.msg);
}
}
});
})
javascript 倒计时获取验证码