手机号码验证和短信验证码60s重新发送验证码
$("#verifyCodeBtn").click(function () { var phone = $("#mobile").val(); $.post(veryfyCodeAction({phone:phone}), function(data) { }); var timer=null; clearInterval(timer);//这句话至关重要 var time=60; timer=setInterval(function(){ console.log(time); if(time<=0){ $("#verifyCodeBtn").val("获取短信验证码") $('#verifyCodeBtn').attr("disabled",false); }else { $('#verifyCodeBtn').attr("disabled",true); $("#verifyCodeBtn").val(time+"秒后重新获取短信验证码") time--; } },1000); }); $("#mobile").blur(function(){ var mobile = $("#mobile").val(); if($.trim(mobile) == '') { $("#mobileSpan").css("color","red") $("#mobileSpan").html("*手机号为空") $("#mobile").focus(); return; } var regExp = /^(86)?((13\d{9})|(15[0,1,2,3,5,6,7,8,9]\d{8})|(18[0,5,6,7,8,9]\d{8}))$/; if(!regExp.test(mobile)){ $("#mobileSpan").css("color","red") $("#mobileSpan").html("*手机号码格式错误"); $("#mobile").focus(); return; } $("#mobileSpan").html("") })