form里两个submit按钮,在onsubmit中判断哪个被点

记下别人的解决方法(有效):

方法1:(已验证过)

<form   name="form1"   onsubmit="show()">   
    
  .....   
    
  <input   type="submit"   name="submit"   id="submit"   value="添加">   
  <input   type="submit"   name="submit"   id="submit"   value="修改">   
</form>       
 <script   language="javascript">   
  function   show()   
  {   
          if   (document.form1.submit.value=="添加")   
          {   
                  alert("你点的是提交");   
          }   
          else   
          {   
                  alert("你点的是修改");   
          }   
  }   
  </script>  

方法二:未验证

<input   type=hidden   name=whatButton>   
  <input   type=submit   onlick="whatButton.value=this.value"   value="aaa">   
  <input   type=submit   onlick="whatButton.value=this.value"   value="bbb">   
  <input   type=submit   onlick="whatButton.value=this.value"   value="ccc">

方法三:已验证

  <!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN">   
  <HTML>   
  <HEAD>   
  <TITLE>   New   Document   </TITLE>   
  <META   NAME="Generator"   CONTENT="EditPlus">   
  <script   language="javascript">   
  <!--   
      function   funcheck()   
      {   
          if(event.srcElement.value == '按钮1')
          {
             alert("The name is empty !");
             return false;
          }
      }   
  //-->   
  </script>   
 </HEAD>   
  <BODY>   
  <input   type=button    onclick="funcheck();"   value="按钮1">   
  <input   type=button    onclick="funcheck();"   value="按钮2">   
  </BODY>   
 </HTML>  

 

posted @ 2015-10-29 13:52  星辰之力  阅读(1266)  评论(0编辑  收藏  举报