1

I got a quick question here. Why do we always bind a checkbox id to the for-attribute in a label? Does it have any purpose? If so, can you please list it out? And also its technical advantage.

Thanks in advance, Madhu.

4

2 回答 2

2

您不必总是将复选框(或任何输入)ID 绑定到标签。它的作用是允许您单击标签以触发单击复选框(或输入)。如果标签元素包装<input>不需要 id/for,这也有效:

<label for="checkbox">Click checkbox</label> <input id="checkbox" type=checkbox>
<label>Click checkbox <input type=checkbox></label>
于 2013-06-06T18:26:46.313 回答
0

是的,它确实有目的。基本上它允许你“点击”它,它也可以用于屏幕阅读器。

答:关于 HTML 标签的“For”属性

于 2013-06-06T18:26:52.703 回答