标准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
。
如何在不创建全局变量的情况下使用表单标签?
最佳答案
使用另一种方式:
<form>
<label>Male <input type="radio"></label>
<label>Female <input type="radio"></label>
</form>
关于javascript - 是否可以在不泄漏全局变量的情况下使用 HTML5 表单标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20703758/