<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
<script language="javascript">
 function check(){
          if(document.test.aaa.value == ""){
             window.alert("aaa不可以为空!");
             return false;
          }else if(document.test.bbb.value == ""){
             window.alert("bbb不可以为空");
             return false;
          }
 }
 function check1(){
          if(check()){
               document.test.action.value == "www.sohu.com";
               document.test.submit();
          }else{
               history.back(-1);
          }
 }
</script>
</head><body><form name="test" method="POST" action="--WEBBOT-SELF--">
<p><input type="text" name="aaa" size="20"></p>
<p><input type="text" name="bbb" size="20"></p>
<p><input type="submit" value="提交" name="B1" onclick="javascript:check();"><input type="reset" value="重置" name="B2"></p>
</form></body></html>----------------------------
我写了一个,但提示信息后还是会post到其它页,怎么能实现提示信息后还停留在表单这页呢?

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    <script language="javascript">
     function check(){
              if(document.test.aaa.value == ""){
                 alert("aaa不可以为空!");
                 document.test.aaa.focus();  
              }else if(document.test.bbb.value == ""){
                 alert("bbb不可以为空");
                 document.test.bbb.focus();
              }
              else
               {
                 document.test.action.value == "www.sohu.com";
                 document.test.submit();
                }
     }
     </script>
    </head><body><form name="test" method="POST" action="--WEBBOT-SELF--">
    <p><input type="text" name="aaa" size="20"></p>
    <p><input type="text" name="bbb" size="20"></p>
    <p><input type="submit" value="提交" name="B1" onclick="check();"><input type="reset" value="重置" name="B2"></p>
    </form></body></html>
      

  2.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    <script language="javascript">
     function check(){
              if(document.test.aaa.value == ""){
                 alert("aaa不可以为空!");
                 document.test.aaa.focus();  
                 return false;
              }
              else if(document.test.bbb.value == ""){
                 alert("bbb不可以为空");
                 document.test.bbb.focus();
                 return false;
              }
              return ture;
     }
     </script>
    </head><body><form name="test" method="POST" action="--WEBBOT-SELF--" onsubmit=" return check();">
    <p><input type="text" name="aaa" size="20"></p>
    <p><input type="text" name="bbb" size="20"></p>
    <p><input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2"></p>
    </form></body></html>