Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们是否需要始终使用 for 属性将输入元素与标签相关联,或者将输入元素保留在标签内也可以?
我想知道什么是最佳实践以及这样包装是否有效。
input包裹在内部是有效的label,并且根据规范,它将标签文本与控件相关联。但是,浏览器支持更适合与id和for属性显式关联的方法,因此这样做是最佳实践。
input
label
id
for
它们的工作原理完全相同。此外,该标准同时接受: http ://www.w3schools.com/tags/tag_label.asp