我选择了一个简单的选择/取消选择选项来检查和取消选中我页面中的复选框。它效果很好,但只有一次。我不知道问题是什么!
请看一下我的代码。你可以看到它的demo here。
HTML code:
<input type="checkbox" id="main" />Select All<br />
<input type="checkbox" class="options" />Item 1<br />
<input type="checkbox" class="options" />Item 2<br />
<input type="checkbox" class="options" />Item 3<br />
<input type="checkbox" class="options" />Item 4<br />
jQuery代码:
$('#main').click(function(e) {
$('.options').attr('checked', this.checked);
});
答案 0 :(得分:3)