If you submit the form via Javascript (ie formElement.submit()
or anything equivalent), then none of the submit buttons are considered successful and none of their values are included in the submitted data.
(如果您通过Javascript提交表单(即formElement.submit()
或等效的任何东西),然后没有提交按钮都被认为是成功的,没有它们的值都包含在提交的数据。)
(Note that if you submit the form by using submitElement.click()
then the submit that you had a reference to is considered active; this doesn't really fall under the remit of your question since here the submit button is unambiguous but I thought I'd include it for people who read the first part and wonder how to make a submit button successful via JS form submission. Of course, the form's onsubmit handlers will still fire this way whereas they wouldn't via form.submit()
so that's another kettle of fish...)((请注意,如果您使用submitElement.click()
提交表单,那么您引用的提交被认为是活动的;这并不属于您的问题的范围,因为这里的提交按钮是明确的,但我认为我将它包含在阅读第一部分并想知道如何通过JS表单提交成功提交按钮的人中。当然,表单的onsubmit处理程序仍然会以这种方式触发,而它们不会通过form.submit()
这样那是另一条鱼......))
If the form is submitted by hitting Enter while in a non-textarea field, then it's actually down to the user agent to decide what it wants here.
(如果通过在非textarea字段中按Enter键来提交表单,那么它实际上是由用户代理决定它想要的内容。)
The specs don't say anything about submitting a form using the enter key while in a text entry field (if you tab to a button and activate it using space or whatever, then there's no problem as that specific submit button is unambiguously used).(规范没有说明在文本输入字段中使用回车键提交表单的任何内容(如果您选择按钮并使用空格或其他任何内容激活它,那么没有问题,因为明确使用了特定的提交按钮)。)
All it says is that a form must be submitted when a submit button is activated, it's not even a requirement that hitting enter in eg a text input will submit the form.(它只是表示必须在激活提交按钮时提交表单,甚至不要求按输入例如文本输入提交表单。)
I believe that Internet Explorer chooses the submit button that appears first in the source;
(我相信Internet Explorer会选择首先出现在源中的提交按钮;)
I have a feeling that Firefox and Opera choose the button with the lowest tabindex, falling back to the first defined if nothing else is defined.(我有一种感觉,Firefox和Opera选择具有最低tabindex的按钮,如果没有其他定义,则回退到第一个定义的按钮。)
There's also some complications regarding whether the submits have a non-default value attribute IIRC.(关于提交是否具有非默认值属性IIRC,也存在一些复杂性。)
The point to take away is that there is no defined standard for what happens here and it's entirely at the whim of the browser - so as far as possible in whatever you're doing, try to avoid relying on any particular behaviour.
(需要注意的是,对于此处发生的事情没有明确的标准,而且完全是浏览器的一时兴起 - 所以尽可能在你正在做的事情中,尽量避免依赖任何特定的行为。)
If you really must know, you can probably find out the behaviour of the various browser versions but when I investigated this a while back there were some quite convoluted conditions (which of course are subject to change with new browser versions) and I'd advise you to avoid it if possible!(如果你真的必须知道,你可能会发现各种浏览器版本的行为,但是当我调查这一段时间后,有一些非常复杂的条件(当然可能会随着新的浏览器版本而改变)并且我建议如果可能的话,你要避免它!)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…