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.
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.
您不必总是将复选框(或任何输入)ID 绑定到标签。它的作用是允许您单击标签以触发单击复选框(或输入)。如果标签元素包装<input>
不需要 id/for,这也有效:
<label for="checkbox">Click checkbox</label> <input id="checkbox" type=checkbox>
<label>Click checkbox <input type=checkbox></label>
是的,它确实有目的。基本上它允许你“点击”它,它也可以用于屏幕阅读器。