识别表单的主要提交按钮

问题描述:

我有一个有几个文本框和两个提交按钮的表单。选择文本框后,按 Enter ,将触发第一个提交按钮。但是,这不是当时应该按下的按钮。我该如何做到这一点,以便当按下 Enter 按钮时,点击第二个提交按钮(或至少是提交按钮的最后一个)?

I have a form which has a few text boxes, and two submit buttons. When a text box is selected, and I press Enter, the first submit button is triggered. However, this is not the button that should be pressed at that time. How can I make it so that when the Enter button is pressed, the second submit button (or at least, the last occurrence of the submit button) clicked?

我有一个目前使用JavaScript的实现,但我希望有一个本地选项。

I have an implementation of this currently using JavaScript, but I'm hoping there is a native option for it.

其获得更多原生JavaScript相当困难。你会在这里需要它。顺便说一句,你注意到的行为是预期的行为。您的html中的第一个提交按钮是一个将随您的标题一起发送的提交按钮。

I guess if you really didn't want to use js, you could just put the other button first and then use css to position them correctly on the page itself.