Is quot;forquot; attribute necessary in HTML label if the target input is nested inside the label?(是“为如果目标输入嵌套在标签内,则 HTML 标签中必需的属性?)
问题描述
我注意到当您将输入元素放入标签元素时,HTML 标签标签不需要for"属性:
I've noticed that a HTML label tag doesn't need the 'for' attribute when you put your input element into the label element:
<label><input type="text">Last name</label>
但我想知道最好的做法是什么.有人可以帮我吗?
But I was wondering what's the best practise. Can anybody help me with that?
谢谢!
推荐答案
它用于屏幕阅读器等的可访问性,即
It's used for accessibility for screen readers and the like i.e.
use_the_label_element_to_make_your_html_forms_accessible
所以你应该使用它.这里有一个 链接 让您相信无障碍的重要性.
So you should use it. And here is a link to convince you about the importance of accessibily.
这里有一个小故事 - 让您的网站易于访问可以使所有用户受益 - 在我有一个女儿并使用婴儿车之前,市政当局为轮椅无障碍所做的努力一直让我感到惊讶.我认为网站遵循相同的规则 - 每个人都受益.
And here is a little story - making your site accessible can benefit all users - i always was amazed at the amount of effort civic authorities went to for wheelchair accessibilty until I had a daughter and use a push chair. I think websites follow the same rule - everyone benefits.
为争议道歉
这篇关于是“为"如果目标输入嵌套在标签内,则 HTML 标签中必需的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是“为"如果目标输入嵌套在标签内,则 HTML 标签中必需的属性?


基础教程推荐
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 动态更新多个选择框 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01