重写表单的checkForm方法,并用if和else解决异步判断的问题。
function checkForm(){ 1 var flag = false; 2 3 $.ajaxSetup({async : false}); 4 5 $.post( ,'captcha='+document.getElementById("captcha").value,function(msg){ if(!parseInt(msg)){layer.alert('验证码错误!',{time:1000});return flag;}else{ 6 7 $.post( ,'username='+document.getElementById("username").value+'&'+'password='+document.getElementById("password").value,function(msg){ if(!parseInt(msg)){layer.alert('用户名或密码错误!',{time:1000});return flag;}else{ 8 9 flag = true;return flag;}});}});10 11 return flag; }