Can a label only refer to input elements?

后端 未结 4 1271
有刺的猬
有刺的猬 2021-02-13 11:16

W3Schools have this to say about labels:

The tag defines a label for an input element. [Emphasis mine]<

4条回答
  •  长发绾君心
    2021-02-13 12:02

    The HTML spec says, about label's "for" attribute, "When present, the value of this attribute must be the same as the value of the id attribute of some other control in the same document. When absent, the label being defined is associated with the element's contents."

    So the id references in "for" should be that of a control. What's a control? The spec basically says any input is a control, as is button, select, or object. So Firefox is technically right -- a div is not a control.

提交回复
热议问题