属性的标签标签可以与正常的div关联吗? [英] Can the label tags for attribute be associated with a normal div?

查看:183
本文介绍了属性的标签标签可以与正常的div关联吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



请让我知道如果可能的话,

Thomas

解决方案不符合规范:


一些元素,并非全部与表单相关,都被分类为
可描述元素。这些元素可以与
标签元素相关联。



buttoninput(如果type属性不处于隐藏状态) keygen
meteroutputprogressselecttextarea

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



另请参阅:


可以指定for属性来指示与
相关联的标题的表单控件。如果指定了该属性,则
属性的值必须是
与document元素相同的Document中的一个labelable元素的ID。如果指定了属性,并且
在Document中有一个元素,其ID等于
的值for属性,并且第一个这样的元素是一个labelable元素,
则那个元素是标签元素的标签控制。


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



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

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

is it valid html under html5 definitions to use a label's "for" value as an id of a normal div element (for example I have made a custom dropdown list implementation which is encased inside a div)

Please let me know if possible,

Thomas

解决方案

Not according to the spec:

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

See also:

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

I do think the question presents a valid use case. I'm not sure what the recommended pattern is for such a scenario, though ARIA attributes might help to make the markup more accessible:

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

这篇关于属性的标签标签可以与正常的div关联吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆