请教各位大侠,SSH整合中,在添加或注册时,已经用JS判断了每个信息,如果个别信息不符合要求,在点击提交时怎么控制着不让提交啊?

解决方案 »

  1.   

    <script>
    function validate(){
       if(!通过)
           return false;
       return true;
    }
    </script><input type="submit" onsubmit="return validate()" />
      

  2.   

    function succorCarCheck(){
    if(document.succorCarForm.succorCarNumber.value==""){
    alert("车辆编号不能为空!");
    return false;
    }
    return ture
    }
    <input type="submit" onsubmit="return succorCarCheck()" />
      

  3.   

    <html>
      <head>
        <title>login.html</title>
    <script type="text/javascript">
    function checkInput(){
                          with(document.login){
                               var name = username.value;
                               var pwd = userpass.value;
      if(username==""){
    alert("请输入用户名");
    return false;
    }
    if(pwd==""){
    alert("请输入密码");
    return false;
    }return true;
                         }
        }
    </script>
    <head>
      <body>
      <h1 align="center"><font size="5" color="black">E-Book电子书店登录系统</font></h1>
      <center><form name="form1" method="post" action="HelloServlet" onsubmit="return checkInput()">
       用户名: <input type="text" name="username"/><br>
       <br>
       密&nbsp;&nbsp;码: <input type="password" name="userpass" width="180px"/><br>
       <br/>
       <input type="submit" value="提 交" onfocus="this.blur()">
       <input type="reset" value="重 置" onfocus="this.blur()">
      </form></center>
      </body>
    </html>
    说明:在表单验证中如果使用with函数(方法)获取了表单名,就必须确保变量名不能与表单的子元素的名字重名,否则会出错,比如表单子元素useName和变量名userName
      

  4.   

    <html> 
      <head> 
        <title>login.html </title> 
    <script type="text/javascript"> 
    function checkInput(){ 
                          with(document.login){ 
                              var name = username.value; 
                              var pwd = userpass.value; 
    if(username==""){ 
    alert("请输入用户名"); 
    return false; 

    if(pwd==""){ 
    alert("请输入密码"); 
    return false; 
    }return true; 
                        } 
      } 
    </script> 
    <head> 
      <body> 
      <h1 align="center"> <font size="5" color="black">E-Book电子书店登录系统 </font> </h1> 
      <center> <form name="form1" method="post" action="HelloServlet" onsubmit="return checkInput()"> 
      用户名: <input type="text" name="username"/> <br> 
      <br> 
      密&nbsp;&nbsp;码: <input type="password" name="userpass" width="180px"/> <br> 
      <br/> 
      <input type="submit" value="提 交" onfocus="this.blur()"> 
      <input type="reset" value="重 置" onfocus="this.blur()"> 
      </form> </center> 
      </body> 
    </html> 
    说明:在表单验证中如果使用with函数(方法)获取了表单名,就必须确保变量名不能与表单的子元素的名字重名,否则会出错,比如表单子元素useName和变量名userName 
      

  5.   

    我想也可以在实体类的setter方法中做好设置吧