html - Enter 上没有提交按钮的表单

标签 html forms form-submit submit-button

对于表单,没有提交按钮,有 1 个文本输入,请按 Enter 提交。

对于表单,没有提交按钮,有超过1个文本输入,不要回车提交。

两者都不应该在 Enter 上提交吗?

<!-- This one do submit on Enter --> 
<form action="/">
  <input type="text" name="firstname" value="Mickey">
</form>

<!-- This one do not submit on Enter --> 
<form action="/">
  <input type="text" name="firstname" value="Mickey">
  <input type="text" name="lastname" value="Jerry">
</form>

最佳答案

If the form has no submit button, then the implicit submission mechanism must do nothing if the form has more than one field that blocks implicit submission, and must submit the form element from the form element itself otherwise.

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission

您可以在此处查看没有提交按钮的表单如何工作: https://www.tjvantoll.com/2013/01/01/enter-should-submit-forms-stop-messing-with-that/#no-submit-buttons

关于html - Enter 上没有提交按钮的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45629219/

相关文章:

jQuery 表单提交 - 如何追加数据?

html - 禁用输入字段的自动完成/自动填充

html - 如何用css创建一个万宝路风格的表格

php - HTML 表单和 PHP 脚本不起作用

javascript - 使用 patchValue 对模板驱动的表单进行初始化

javascript - 使用 jQuery 显示警告

html - 带有滚动和自动大小列的表格

javascript - 如何使用 javascript 检查 URL 是否存在

javascript - 如何在提交时重置输入表单(ReactJS)

javascript - 发布没有 <form> 标签的表单有什么缺点吗