选中/取消选中所有复选框 [英] check/uncheck all checkboxes
本文介绍了选中/取消选中所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个复选框来检查/取消选中所有其他复选框。
I am trying to have a checkbox that checks/unchecks all the other checkboxes.
我正在使用此代码:
$("#checkall").toggle(
function () {
$(".kselItems").attr('checked', 'checked');
},
function () {
$(".kselItems").removeAttr("checked");
});
这可以正常工作,但由于某种原因,id checkall
(应该使每件事情都工作)不会保持检查。
This works fine, but for some reason, the checkbox with the id checkall
(the one that should make every thing work) never stays checked.
如何解决?
推荐答案
请尝试此
$("#checkall").click(function() {
$(".kselItems").attr('checked', this.checked);
});
演示: http://jsfiddle.net/naveen/azkPR/
这篇关于选中/取消选中所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文