是“为"如果目标输入嵌套在标签内,则 HTML 标签中必需的属性? [英] Is "for" attribute necessary in HTML label if the target input is nested inside the label?

查看:35
本文介绍了是“为"如果目标输入嵌套在标签内,则 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 标签中必需的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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