日期:2014-05-16  浏览次数:20267 次

请问,如何阻止提交错误的信息,如注册用户名的时候,我可以用AJAX验证,但是我提交的时候,它可以把错误的给提交过去,我要实现的是,如
请问,如何阻止提交错误的信息,如注册用户名的时候,我可以用AJAX验证,但是我提交的时候,它可以把错误的给提交过去,我要实现的是,如果页面上有错误的信息,点击提交,整个页面不会变,会把错误信息都显示出来  
是不是应该把FALSE赋给一个值err.提交的时候判断err是不是为false,如果为false,就提交不了?理论我知道,但是代码就不清楚了,望大家给个代码参考一下,谢谢

------解决方案--------------------
onclick= "return check() "

function check(){
if(....){
//do....
}else if(...){

}....
return ...
}
------解决方案--------------------
<form name= "myForm " method= "post " action= " " onsubmit= "return check() ">
<table> <tr> <td> <input name= "test " value= " "> </td> </tr> </table>
<input type= "submit " name= "submit ">
</form>
<script>
function check()
{
if(document.myForm.test.value== " ")
{
alert( "不能为空 ")
return false;
}
return true;

}
</script>