gpt4 book ai didi

html - 属性的 label 标签可以与普通的 div 相关联吗?

转载 作者:技术小花猫 更新时间:2023-10-29 12:11:21 25 4
gpt4 key购买 nike

在 html5 定义下使用标签的“for”值作为普通 div 元素的 id 是否有效(例如,我制作了一个包含在 div 中的自定义下拉列表实现)

如果可能请告诉我,

托马斯

最佳答案

不符合规范:

Some elements, not all of them form-associated, are categorized as labelable elements. These are elements that can be associated with a label element.

"button" "input" (if the type attribute is not in the hidden state) "keygen" "meter" "output" "progress" "select" "textarea"

http://www.w3.org/TR/html5/forms.html#category-label

另见:

The for attribute may be specified to indicate a form control with which the caption is to be associated. If the attribute is specified, the attribute's value must be the ID of a labelable element in the same Document as the label element. If the attribute is specified and there is an element in the Document whose ID is equal to the value of the for attribute, and the first such element is a labelable element, then that element is the label element's labeled control.

http://www.w3.org/TR/html5/the-label-element.html#attr-label-for

我确实认为这个问题提供了一个有效的用例。我不确定针对这种情况推荐的模式是什么,尽管 ARIA 属性可能有助于使标记更易于访问:

https://developer.mozilla.org/en/Accessibility/ARIA/forms/Basic_form_hints https://developer.mozilla.org/Special:Tags?tag=ARIA

关于html - 属性的 label 标签可以与普通的 div 相关联吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11705956/

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