为什么使用“for”关键字绑定HTML中的标签? [英] Why use the "for" keyword to bind a label in HTML?

查看:116
本文介绍了为什么使用“for”关键字绑定HTML中的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

什么是HTML标签中的For属性?

我一直在试图找出答案。在HTML中使用标签时使用for =的原因是什么?

 < form> 
< label for =male>男性< / label>
< input type =radioname =sexid =male/>
< br />
< label for =女性>女性< / label>
< input type =radioname =sexid =female/>
< / form>

如果需要,那么HTML 5中是否有相同的内容?或者它是相同的?

解决方案

它在标签上单击焦点输入元素,。



在您发布的示例中,您只需点击单词男性 收音机按钮以便它被选中。如果没有这个,你有一个小得多的目标点击...


如果需要,那么HTML5中是否存在一些等价物呢?这不是必需的,但对于具有直接表单元素的标签来说,这是不错的做法,对于在表单中没有对应标签的标签是很有意义的)。



HTML 5的语法相同。


Possible Duplicate:
What is the For attribute for in an HTML tag?

I have been trying to find this out. What is the reason for using the "for=" when you use a label in HTML?

<form>
  <label for="male">Male</label>
  <input type="radio" name="sex" id="male" />
  <br />
  <label for="female">Female</label>
  <input type="radio" name="sex" id="female" />
</form>

If it's needed then is there some equivalent in HTML 5 or is it the same?

解决方案

It makes a click on the label focus the input element it is for.

In the example you posted, you simply click on the word Male or the radio button in order for it to get selected. Without this, you have a much smaller target to click...

If it's needed then is there some equivalent in HTML 5 or is it the same?

It is not required, but is good practice for labels that have a direct form element to focus on (it wouldn't make much sense for a label that doesn't have a counterpart on a form).

The syntax is the same for HTML 5.

这篇关于为什么使用“for”关键字绑定HTML中的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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