zoukankan      html  css  js  c++  java
  • 关于提交表单的问题

    关于提交表单的问题:
    <input type="submit" value="提交" />点击后无论是否符合要求都会提交表单,如何需要控制只有符合要求的才可以提交,需要如下:
    <input type="button" value="提交" onclick="check()"/>
    function check()
    {
     var name=document.getElementById("txtUserName").value;
     if(name=="")
    {
     return false; 
    }
    else
    {
     document.form1.submit();
    }
    }

    注意其中的form1为form的name属性
    第一种情况:  
      通过button的onClick处理:  
      <input   name="Submit"   value="确定"   type="button"   onclick="IsInEmpty()">  
      <script   language="javascript">  
      function   IsInEmpty()   {    
      if(document.all.textfield2.value.replace(/\s/g,"")=="")   {    
        window.alert("请签名");    
      }   else   {  
        document.form的名字.submit();    
      }    
      }  
      </script>  
       
      第二种:在form的onSubmit中处理  
      <form   name="theForm"   ...   onSubmit="IsInEmpty()">  
       
      <script   language="javascript">  
      function   IsInEmpty()   {    
      if(document.all.textfield2.value.replace(/\s/g,"")=="")   {  
        window.alert("请签名");    
        return   false;    
      }   else   {    
      window.alert("dd");    
      return   true;    
      }    
      }  
      </script>  
      2者区别:  
      一个通过button来产生一个事件,然后在事件中,根据条件来决定是否提交表单,不过,得自己写上document.form的名字.submit();    
      另外一个通过onSubmit来处理事件,根据这个事件的返回的true/false来决定是否提交表单  

  • 相关阅读:
    SpringBoot实现原理
    常见Http状态码大全
    forward(转发)和redirect(重定向)有什么区别
    1094. Car Pooling (M)
    0980. Unique Paths III (H)
    1291. Sequential Digits (M)
    0121. Best Time to Buy and Sell Stock (E)
    1041. Robot Bounded In Circle (M)
    0421. Maximum XOR of Two Numbers in an Array (M)
    0216. Combination Sum III (M)
  • 原文地址:https://www.cnblogs.com/wucf2004/p/575576.html
Copyright © 2011-2022 走看看