gpt4 book ai didi

html - 我可以为一个表单元素使用多个标签吗?

转载 作者:太空狗 更新时间:2023-10-29 13:40:57 24 4
gpt4 key购买 nike

以下是 HTML5 中 label 元素的有效用法吗?

<label for="select">Some text</label>
<select id="select">
...
</select>
<label for="select">...more text</label>

HTML5 specs似乎没有什么可说的。

编辑:这个问题现在已经过时了。在当前的措辞中,很明显一个元素可以有多个标签(但反之则不行):

Labelable elements have a NodeList object associated with them that represents the list of label elements, in tree order, whose labeled control is the element in question.

最佳答案

您可以有多个标签指向同一个表单控件,这是合法的。

根据 HTML 4 Documentation :

The LABEL element may be used to attach information to controls. Each LABEL element is associated with exactly one form control.

The for attribute associates a label with another control explicitly: the value of the for attribute must be the same as the value of the id attribute of the associated control element. More than one LABEL may be associated with the same control by creating multiple references via the for attribute.

关于html - 我可以为一个表单元素使用多个标签吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24204063/

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