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

查看:225
本文介绍了是“为"如果目标输入嵌套在标签内,则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天全站免登陆