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

标签 html forms

以下是 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/

相关文章:

javascript - 如何调整Nogray时间选择器输入的宽度?

html - 选择选项 *selected* 属性在 chrome 中不起作用

forms - ExtJS 为什么 form.getValues() 只返回 "1"而不是 "0"用于复选框状态?

forms - 一个 &lt;input&gt; 中的 HTTP multipart/form-data 多个文件

html - 如何编写继承外部 css(html-email)的 css?

html - 调整 Bootstrap 下拉列表项中多个图标或文本之间的间距

javascript - 滚动条导致页面移动

html - Bootstrap : background image unresponsive in jumbotron class upon screen resizing

html - Bootstrap 4 中单行的多个表单组

javascript - 从动态创建的 html 表单按钮调用 Javascript 函数