好的,我错过了什么?我有:
<form>
    <input type="checkbox" name="showRatings" value="1" checked>
    <label for="showRatings">Show Ratings</label>
</form>
当我点击"显示评级"文本时,复选框不会切换.我知道这很简单.
Dav*_*vid 84
我相信label元素链接到id属性,而不是name属性.试试这个:
<form>
  <input type="checkbox" name="showRatings" id="showRatings" value="1" checked>
  <label for="showRatings">Show Ratings</label>
</form>
参考这里.
小智 6
当input元素在标签内部时,我们不需要元素上的id和标签上的'for'属性,但是当它在外面时我们需要它.
<label>
    Foo
    <input name="foo" type="checkbox" />
</label>
单击"Foo"将触发复选框的切换