html5 – 我可以为表单元素使用多个标签吗?

前端之家收集整理的这篇文章主要介绍了html5 – 我可以为表单元素使用多个标签吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
以下是 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.

猜你在找的HTML5相关文章