前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >理解HTML工作原理——HTML form隐式提交

理解HTML工作原理——HTML form隐式提交

作者头像
大神带我来搬砖
发布2018-05-02 14:06:33
1.5K0
发布2018-05-02 14:06:33
举报

有时在HTML页面form的input里按了回车键会提交该表单,并且form的submit按钮的click事件也会被触发.这是什么原理呢?是因为form的隐式提交(Implicit submission)机制 在https://www.w3.org/TR/html52/sec-forms.html#implicit-submission中是这么解释的

A form element’s default button is the first Submit Button in tree order whose form owner is that form element.

form的第一个submit按钮作为default button

If the user agent supports letting the user submit a form implicitly (for example, on some platforms hitting the "enter" key while a text field is focused implicitly submits the form), then doing so for a form whose default button has a defined activation behavior must cause the user agent to run synthetic click activation steps on that default button.

浏览器隐式提交时要触发default button的click事件.在某些平台上,text field获得焦点时,按回车键会触发隐式提交

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. For the purpose of the previous paragraph, an element is a field that blocks implicit submission of a form element if it is an input element whose form owner is that form element and whose type attribute is in one of the following states: Text, Search, URL, Telephone, E-mail, Password, Local Date and Time, Date, Month, Week, Time, Number

form里有超过一个的input时,必须阻止隐式提交

在早期的HTML规范中,还有如下描述

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.

如果form里只有一个text input,那么那个input按回车要触发form提交 地址是https://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.03.24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档