var wait=60; |
function time(o) { |
if (wait == 0) { |
$( '#btn_yzm' ).removeAttr( "disabled" ); |
$( '#btn_yzm' ).val( "获取验证码" ); |
wait = 60; |
} else { |
//o.setAttribute("disabled", true); |
$( '#btn_yzm' ).attr( "disabled" , true ); |
$( '#btn_yzm' ).val( "重新发送(" + wait + ")" ); |
|
wait--; |
setTimeout( function () { |
time(o) |
}, |
1000) |
} |
} |
function checkMobile(sMobile){ |
if (!(/^1[3|4|5|8|7][0-9]\d{4,8}$/.test(sMobile))){ |
return false ; |
} |
return true ; |
} |
document.getElementById( "btn_yzm" ).onclick= function (){ |
if ($( "#mobile" ).val() == '' ){ |
alert( "请输入手机号" ); |
return false ; |
} |
if (!checkMobile($( "#mobile" ).val()){ |
alert( "请输入您的手机号码!" ); |
return false ; |
} |
|
$.ajax({ |
type: "POST" , |
url: "<?php echo $this->createUrl('user/yzm')?>" , |
data: "y=1&sj=" +$( '#mobile' ).val(), |
success: function (msg){ |
console.log(msg); |
|
if (msg == '短信发送成功' ){ |
|
alert( "发送验证码成功" ); |
time( this ); |
} else { |
alert( "发送验证码失败 --" + msg); |
return false ; |
} |
} |
}); |
} |