10、遍历checkbox
$('input:checkbox').each(function (index, domEle) {
//写入代码
});
11、全部选中
$('input:checkbox').each(function() {
$(this).attr('checked', true);
});
12、全部取消选择
$('input:checkbox').each(function () {
$(this).attr('checked',false);
});
转自 http://www.jb51.net/article/46469.htm
项目代码
if($("#headcheckbox1").attr("checked")=="checked"){
console.log("判断复选框是否选中...");
}
if(document.getElementById("headcheckbox1").checked){
$('input:checkbox').each(function() {
$(this).prop('checked', true);
});
console.log("复选框全选.....");
}else{
$('input:checkbox').each(function () {
//$(this).prop('checked', true); jquery1.1第一次全选和取消起作用,第二次失效
$(this).removeAttr("checked");
});
console.log("复选框取消全选.....");
}