标准HTML 5 form label wants an ID to link the label to the input。
<form>
<label for="male">Male</label>
<input type="radio" id="male"/>
<label for="female">Female</label>
<input type="radio" id="female"/>
</form>
正如大多数JS开发人员所知, using IDs leaks globals - 在这种情况下,会创建window.male
和window.female
。
如何在不创建全局变量的情况下使用表单标签?
答案 0 :(得分:10)
使用另一种方式:
<form>
<label>Male <input type="radio"></label>
<label>Female <input type="radio"></label>
</form>