关于HTML标签的“For”属性 [英] Regarding the HTML Label's "For" Property
问题描述
考虑以下两行代码(从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屋!