简体   繁体   English

带2个提交按钮的HTML表单

[英]HTML form with 2 submit buttons

I am having a HTML form with 2 submit buttons. 我有一个带有2个提交按钮的HTML表单。 One is for submitting the form and other one is for executing a Java Script function. 一种是提交表单,另一种是执行Java Script函数。 When I click the button to execute the Java script function it tries to submit the form. 当我单击按钮以执行Java脚本功能时,它将尝试提交表单。 How can I handle this situation. 我该如何处理这种情况。 That is I want the form to be submitted when the submit button is clicked and Java script function to run when the other button is clicked. 那就是我希望在单击“提交”按钮时提交表单,并在单击其他按钮时运行Java脚本功能。

在您的“ JavaScript”提交按钮中,执行代码后返回false,这将阻止它提交表单。

Why are you using a type="submit" button for the javascript action? 为什么要对JavaScript操作使用type="submit"按钮?

Instead use a <button onclick="myFunction()">Button Text</button> 而是使用<button onclick="myFunction()">Button Text</button>

If you are resetting the form you could use type="reset" 如果您要重置表格,则可以使用type="reset"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM