Jquery发送验证码倒计时
Html
获取验证码" />
Jquery
var wait=60; function time(o) { if (wait == 0) { o.removeAttribute("disabled"); o.value="点击获取验证码"; wait = 60; } else { o.setAttribute("disabled", true); o.value="重新发送(" + wait + ")"; wait--; setTimeout(function() { time(o) }, 1000) } }function getcode( index )
{
index.setAttribute("disabled", true);
var phone = $("input[name='phone']").val();
var reg = /^1[34578]\d{9}$/;
if( !reg.test(phone) )
{
index.removeAttribute("disabled");
$("input[name='phone']").focus();
}else
{
$.post('您要验证的接口',{您要传递的参数},function( msg ){
if( msg == 'success' )
{
time( index );
}else
{
//这里处理你需要的业务
index.removeAttribute("disabled");
}
},'json');
}
}
document.getElementById("yzm").onclick=function(){getcode(this);}