是否可以使用HTML5表单标签而不泄漏全局变量?

时间:2013-12-20 12:33:34

标签: javascript html5 forms globals

标准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.malewindow.female

如何在不创建全局变量的情况下使用表单标签?

1 个答案:

答案 0 :(得分:10)

使用另一种方式:

<form>
    <label>Male <input type="radio"></label>    
    <label>Female <input type="radio"></label>    
</form>
相关问题