本文共 1010 字,大约阅读时间需要 3 分钟。
I have a form that has three submit buttons as follows:
The row of buttons is a mix of submit, reset and javascript buttons. The order of buttons is subject to change but in any case the save button remains between prev and next buttons. The problem here is that when a user hits "enter" to submit the form, the post variable "COMMAND" contains "Prev"; normal, as this is the first submit button on the form. I however want the "Next" button to be triggered when the user submits the form via enter button. Kind of like setting it as the default submit button, even though there are other buttons before it.
解决方案
My suggestion is don't fight this behaviour. You can effectively alter the order using floats. For example:
with:
#buttons { overflow: hidden; }
#buttons input { float: right; }
will effectively reverse the order and thus the "Next" button will be the value triggered by hitting enter.
This kind of technique will cover many circumstances without having to resort to more hacky Javascript methods.
转载地址:http://pvspa.baihongyu.com/