问题描述
我有一个 HTML 表单,其中使用了多个按钮.问题是无论我点击哪个按钮,即使按钮不是提交"类型,表单也会被提交.例如像这样的按钮:,导致表单提交.
I have a HTML form where I use several buttons. The problem is that no matter which button I click, the form will get submitted even if the button is not of type "submit". e.g. Buttons like :<button>Click to do something</button>
, result in form submission.
为这些按钮中的每一个都执行一个 e.preventDefault()
非常痛苦.
It's quite painful to do an e.preventDefault()
for each one of these buttons.
我使用 jQuery 和 jQuery UI,网站是 HTML5.
I use jQuery and jQuery UI and the website is in HTML5.
有没有办法禁用这种自动行为?
Is there a way to disable this automatic behavior?
推荐答案
按钮,如 Click to do something
是提交按钮.
Buttons like <button>Click to do something</button>
are submit buttons.
设置 type=button"
来改变它.type="submit"
是默认值(如 由 HTML 规范指定):
Set type="button"
to change that. type="submit"
is the default (as specified by the HTML spec):
缺失值默认和无效值默认为提交按钮状态.
这篇关于禁用表单自动提交按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!