带有2个提交按钮的HTML表单

时间:2022-11-24 20:11:42

I am having a HTML form with 2 submit buttons. One is for submitting the form and other one is for executing a Java Script function. When I click the button to execute the Java script function it tries to submit the form. 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.

我有一个带有2个提交按钮的HTML表单。一个用于提交表单,另一个用于执行Java脚本功能。当我单击按钮执行Java脚本函数时,它会尝试提交表单。我该如何处理这种情况。这就是我希望在单击提交按钮时提交表单,并在单击其他按钮时运行Java脚本功能。

2 个解决方案

#1


0  

Why are you using a type="submit" button for the javascript action?

为什么你使用type =“submit”按钮进行javascript操作?

Instead use a <button onclick="myFunction()">Button Text</button>

而是使用

If you are resetting the form you could use type="reset"

如果您要重置表单,可以使用type =“reset”

#2


0  

In your "JavaScript" submit button, return false after executing your code, that should prevent it from submitting the form.

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

#1


0  

Why are you using a type="submit" button for the javascript action?

为什么你使用type =“submit”按钮进行javascript操作?

Instead use a <button onclick="myFunction()">Button Text</button>

而是使用

If you are resetting the form you could use type="reset"

如果您要重置表单,可以使用type =“reset”

#2


0  

In your "JavaScript" submit button, return false after executing your code, that should prevent it from submitting the form.

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