gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:33:51 26 4
gpt4 key购买 nike

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

此外,根据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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com