Home  >  Article  >  Web Front-end  >  form 表单中onsubmit()与submit()区别

form 表单中onsubmit()与submit()区别

WBOY
WBOYOriginal
2016-06-01 09:54:531455browse

onsubmit()是一个js事件,该事件会在表单提交时触发。想了解更多onsubmit()知识可以看这篇文章。

而submit是一个方法,该方法用于提交form表单。想了解更多submit知识可以看这篇文章。

由此可以看出二者操作的前后顺序,onsubmit()在前,submit在后。

下面是onsubmit()与submit()区别的实例。

<code class="language-html"><script>
function fun()
{
   alert("form_submit");
}
</script>

<form onsubmit="fun()">
<input type="submit" id="aaa" value="submit">   <!--能弹出form_submit-->
<input type="button" id="bbb" value="onCliCk_submit" onclick="doCument.forms[0].submit()">
<!--
表单会提交,但是不会运行fun() 原因是 onsubmit事件不能通过此种方式触发,直接用脚本doCumetn.formName.submit()提交表单是不会触发表单的onsubmit()事件的
-->
    <input type="button" id="bb1" value="onCliCk_onsubmit" onclick="doCument.forms[0].onsubmit()">

<!--会触发fun()参数-->
</form></code>

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn