关于HTML标签的“For”属性 [英] Regarding the HTML Label's "For" Property

查看:126
本文介绍了关于HTML标签的“For”属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下两行代码(从w3schools.com复制HTML< label> for Attribute):

 < label for =male> Male< / label> 
< input type =radioname =sexid =male/>

我无法发现上述标签的for属性的确切用途。正如你所看到的,它现在被设置为male(匹配输入控件的id)。

到目前为止我所读到的是,上面的代码将会'联合'和'绑定'输入控件的标签。
所以我的问题是,这到底意味着什么?



关联标签和输入控件的结果究竟是什么?

由于这种关联,标签和/或输入是否有新的行为?

解决方案

可通过添加一个与控件关联的<标签可点击。点击它选择控件。对收音机/复选框尤其有用。它还对视障人士的屏幕阅读器具有可访问性。


Considering the following 2 lines of code (copied from w3schools.com > "HTML < label > for Attribute"):

  <label for="male">Male </label>
  <input type="radio" name="sex" id="male" />

I am having trouble discovering the exact purpose of the above label's "for" property. As you can see it is currently set to "male" (to match the id of the input control).

All I have read so far is that the above code will 'associate' and 'bound' the label with the input control. So my question is, what exactly does this mean?

What exactly are the results of associating the label to the input control?
Does the label and/or input have new behaviours as a result of this 'association'?

解决方案

A label that is associated with a control via for will be clickable. Clicking it selects the control. Highly useful with radio/checkboxes in particular. It also has accessibility implications for screen readers for the visually impaired.

这篇关于关于HTML标签的“For”属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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