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 标签中必需的属性?


- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01