我应该将输入标签放在标签标签内吗? [英] Should I put input tags inside a label tag?

查看:68
本文介绍了我应该将输入标签放在标签标签内吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道是否有关于标签和输入标签的最佳做法:

经典方式:

 < label for =myinput>我的文字< / label> 
< input type =textid =myinput/>

 < label for =myinput>我的文本
< input type =textid =myinput/>
< / label>


解决方案

从w3:标签本身可能位于相关控件之前,之后或周围。


$ b

< label for =lastname> Last Name< / label> ;< input type =textid =lastname/>



< input type =textid = lastname/>< label for =lastname> Last Name< / label>


$ b



< label> < input type =textname =lastname/>姓氏< / label>

注意第三种技术不能当表格用于布局时使用,在一个单元格中的标签和在另一个单元格中的相关表单字段。



任何一个都是有效的。我喜欢使用第一个或第二个示例,因为它为您提供了更多样式控制。


I was just wondering if there is a best practice concerning label and input tag :

classic way:

<label for="myinput">My Text</label>
<input type="text" id="myinput" />

or

<label for="myinput">My Text
   <input type="text" id="myinput" />
</label>

解决方案

From w3: The label itself may be positioned before, after or around the associated control.

<label for="lastname">Last Name</label>
<input type="text" id="lastname" />

or

<input type="text" id="lastname" />
<label for="lastname">Last Name</label>

or

<label>
   <input type="text" name="lastname" />
   Last Name
</label>

Note that the third technique cannot be used when a table is being used for layout, with the label in one cell and its associated form field in another cell.

Either one is valid. I like to use either the first or second example, as it gives you more style control.

这篇关于我应该将输入标签放在标签标签内吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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