Use Javascript to change which submit is activated on enter key press

前端 未结 6 1964
深忆病人
深忆病人 2021-01-01 12:09

I have a form on an HTML page with multiple submit buttons that perform different actions. However, when the user is typing a value into a text input and hit enters, the bro

6条回答
  •  旧时难觅i
    2021-01-01 12:54

    How about using CSS? You can just set the first button, your default button outside of the visible area of the screen with a "position: absolute; left: -200px; top: -200px;". As far as I remeber, it will not be ignored by any browser, because it is not invisible. This works just fine:

    ... ...

    And the earth gets saved ...

提交回复
热议问题