[英]Is it possible to use HTML5 form labels without leaking globals?
The standard HTML 5 form label wants an ID to link the label to the input . 标准HTML 5表单标签需要ID来将标签链接到输入 。
<form>
<label for="male">Male</label>
<input type="radio" id="male"/>
<label for="female">Female</label>
<input type="radio" id="female"/>
</form>
As most JS developers know, using IDs leaks globals - in this case, window.male
and window.female
are created. 正如大多数JS开发人员所知, 使用ID泄漏全局变量 - 在这种情况下,会创建window.male
和window.female
。
How can I use form labels without creating globals? 如何在不创建全局变量的情况下使用表单标签?
use the other way: 使用另一种方式:
<form>
<label>Male <input type="radio"></label>
<label>Female <input type="radio"></label>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.