我有一个没有提交按钮的文本框,如下所示:
<html>
<form action="http://www.google.com">
<input type="text"/>
</form>
</html>
当文本框被选中并按下回车键时,表单将被提交,谷歌页面将被显示。 但是,如果我有两个如下所示的文本框:
<html>
<form action="http://www.google.com">
<input type="text"/>
<input type="text"/>
</form>
</html>
现在如果我按下提交按钮什么都不会发生。
谁能在这里解释一下:
i) 为什么在第一种情况下会提交表单?
ii) 为什么在第二种情况下表单没有提交?
最佳答案
When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.
禁用此行为的最简单方法是添加一个隐藏的输入字段。
关于javascript - 单个文本框和提交行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10330416/