html - 在现代 Web 开发中对输入字段使用 "name"属性是否多余?

标签 html forms input

我注意到很多网站的表单包含输入字段,即使它不用于样式或脚本目的,也指定了“名称”属性!

此外,根据the official document关于 HTML 文档中的表单 ...

name = cdata [CI] This attribute names the element so that it may be referred to from style sheets or scripts. Note. This attribute has been included for backwards compatibility. Applications should use the id attribute to identify elements.

所以,我的问题是:这个属性是否应该只用于样式和脚本目的?

提前致谢!


编辑: 特别是,是否可以避免将此属性与“文本”类型的输入字段一起使用(当没有样式或脚本目的时)?


编辑 2: 所以,您几乎已经证实了我的想法:“名称”属性将在进一步的 HTML 规范/标准中被弃用!!!???它仍然“活着”只是为了向后兼容 ...在某些情况下可以避免,但仍然有一些情况(例如单选按钮)是必要的!

最佳答案

我想您会发现几乎每个站点都会有带有 name 属性的输入。我认为它不会很快消失。

The name attribute specifies a name for an input element.

The name attribute is used to identify form data after it has been submitted to the server, or to reference form data using JavaScript on the client side.

Note: Only form elements with a name attribute will have their values passed when submitting a form.

source

关于html - 在现代 Web 开发中对输入字段使用 "name"属性是否多余?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1813085/

相关文章:

Javascript网络爬虫确认确认框

html - css 背景图像不会在 IE 或 Chrome 中显示

javascript - 使用 jQuery 填充隐藏文本输入

javascript - JQuery 搜索不再有效

javascript - 通过 CSS 缩放网页上的所有元素

javascript - 尝试制作表格来计算复利

html - 按钮未对齐以选择表单

java,在for循环中保存输入

c - 使用输入重定向读取文件,然后使用键盘接受输入

jquery - Bootstrap 表单输入仅接受文本