我觉得可以把 onSubmit()方法写在 form的 onsubmit事件中 onSubmit()方法成功返回true 失败就是flase

解决方案 »

  1.   

    很感谢你的回答,你所说的方法我也试过,当输入框中为空值时按回车,会调用自己定义的onSubmit,但因为是空值所以不能有提交这个动作,通过脚本可屏蔽掉后续的语句,但是如此一来默认的提交又会执行,这又是不允许的!
      

  2.   

    问题解决了,谢谢各位的回答,最终代码如下:
    <html>    
      <head>    
      <script>    
            function  onSubmit()  { 
        if(document.form1.text1.value==""){
    alert("false");
    return false;
        }
        return true;     
            }    
      </script>    
      </head>    
      <body>    
            <form onSubmit="return onSubmit();" name="form1">    
                  <table  width=200  height=200>    
                        <tr>    
                              <td>    
                                    <input  type="text"  name="text1">    
                              </td>    
                              <td>    
                                    <input  type="button"  value="submit"  name="sub1"  onclick="onSubmit();">    
                              </td>    
                        </tr>    
                  </table>    
            </form>    
      </body>    
    </html>
    我前面也这样做过,只因在form表单中的onSubmit事件中没有return,所以没效果