为什么有一个文本输入的FORM输入,而有两个文本INPUT的输入没有? [英] Why does a FORM with one text INPUT submit on enter while one with two text INPUTs does not?

查看:129
本文介绍了为什么有一个文本输入的FORM输入,而有两个文本INPUT的输入没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是一个至少包含两个INPUT的表单(包含至少两个INPUT没有隐藏)在按回车时不会提交。



(任何脚本都没有提交/按钮/输入[type = submit]里面)



查看这个 jsfidle 。这种行为有解释/标准吗?

 < form id =form1method =POST> 
< p>是否提交:< / p>
< input type =textplaceholder =focus and press enter/>
< / form>

< form id =form2method =POST>
< p>是否< strong>不&< / strong>提交:其中/ p为H.
< input type =textplaceholder =does not submit/>
< input type =textplaceholder =/>
< / form>


解决方案

此行为是在HTML 2.0规范中引入的。有关更多详情,请参阅以下文章:

表单提交和ENTER键?


当表单中只有一个单行文本输入字段时,
用户代理应接受该字段中的Enter作为提交
表单的请求


来源: W3C规范


I have just found out that a FORM containing only one INPUT (not hidden) will automatically submit when pressing Enter.

But a form containing at least two INPUTS (not hidden) will NOT submit when pressing enter.

(None of the scripts have a submit/button/input[type=submit] inside)

Take a look at this jsfidle. Is there an explanation/standard for this behavior?

<form id="form1" method="POST">
    <p>Does submit:</p>
    <input type="text" placeholder="focus and press enter"/>
</form>

<form id="form2" method="POST">
    <p>Does <strong>not</strong> submit:</p>
    <input type="text" placeholder="does not submit"/>
    <input type="text" placeholder=""/>
</form>

解决方案

This behaviour was introduced in the HTML 2.0 specification. See the following article for more details:

Form submission and the ENTER key?

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

Source: W3C Specs

这篇关于为什么有一个文本输入的FORM输入,而有两个文本INPUT的输入没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆