日期:2014-05-16  浏览次数:20472 次

调用form.submit()方法不同,而结果也不同?
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN ">
<HTML>
  <HEAD>
    <TITLE>   New   Document   </TITLE>
    <META   NAME= "Generator "   CONTENT= "EditPlus ">
    <META   NAME= "Author "   CONTENT= " ">
    <META   NAME= "Keywords "   CONTENT= " ">
    <META   NAME= "Description "   CONTENT= " ">
  </HEAD> <SCRIPT   LANGUAGE= "JavaScript ">
  <!--
function   cc()
{
                alert( "cc ");
              document.forms[0].submit();

}
function   check()
{
        alert( "false ");
return   false;
}
  //-->
  </SCRIPT>

  <BODY>
    <form   name= "form1 "   id= "form1 "   onsubmit= "return   check(); ">
    <input   type= "button "   onclick= "cc() "   value= "submit "/>
    <input   type= "submit "   value= "submit ">
    </form>
  </BODY>
</HTML>
为何第一个submit不触发onsubmit事件呢?

------解决方案--------------------
改成这样就好了:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= " ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
</HEAD> <SCRIPT LANGUAGE= "JavaScript ">
<!--
function cc()
{
alert( "cc ");
//document.forms[0].submit();
document.getElementById( "btnSubmit ").click();
}
function check()
{
alert( "false ");
return false;
}
//-->
</SCRIPT>

<BODY>
<form name= "form1 " id= "form1 " onsubmit= "return check(); ">
<input type= "button " onclick= "cc() " value= "submit "/>
<input type= "submit " value= "submit " id= "btnSubmit ">
</form>
</BODY>
</HTML>

我在做一些类似的问题时也遇到过跟你一样的问题,原因不得而知,一般都是通过对一个type为submit的按钮的click事件来实现对表单的提交。