Stop user from using enter to pass a form

2019-07-21 16:39发布

Due to an issue relating to a horrible mobile device (that work has given me no choice but to work with) I have to stop the use of the enter key from registering in form in HTML. The only way I'd like the data to be submitted is when the submit button is pressed.

Hope this is enough to help work out my problem! If not feel free to ask more.

标签: html forms
3条回答
何必那么认真
2楼-- · 2019-07-21 17:19

You can use an onsubmit handler to prevent the form from being submitted in cases where it wasn't submitted in the way you wanted it to be. Just return false from the handler to cancel the submission.

查看更多
我命由我不由天
3楼-- · 2019-07-21 17:27

See here for an example.

查看更多
男人必须洒脱
4楼-- · 2019-07-21 17:38

Try this submit button:

<input type="button" value="Submit" onclick="document.forms[0].submit();" />

Instead of using type="submit", type="button" won't bind the enter key to this button.

查看更多
登录 后发表回答