简体   繁体   English

标签标签包装输入元素是否有效?

[英]is wrapping input element by label tag valid?

Do we need to use always the for attribute to associate input element to a label or keeping input element inside the label also fine? 我们是否需要始终使用for属性将输入元素关联到标签,还是将输入元素保持在标签内也可以?

I want to know what is the best practice and whether it is valid to wrap like that. 我想知道什么是最佳做法,以及用这种方法包装是否有效。

It is valid to wrap input inside label , and by the specifications, it associates the label text with the control. input包装在label内是有效的,并且根据规范,它会将标签文本与控件关联。 However, browser support is better for the approach where the association is explicit with id and for attribute, so doing so is the best practice. 然而,浏览器支持的方式更好地所在的公会是明确与idfor属性,所以这样做是最好的做法。

They work exactly the same. 它们的工作原理完全相同。 Also, the standard accepts both : http://www.w3schools.com/tags/tag_label.asp 此外,该标准还接受以下两种: http : //www.w3schools.com/tags/tag_label.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM