JS 全选、全不选、反选

function checkReturn(obj) {
var objIds = obj.value;
//当没有选中某个子复选框时,checkboxall取消选中
if (!$("#subcheck").checked) {
$("#checkboxall").attr("checked", false);
}
// 获取subcheck的个数
var chsub = $("input[type='checkbox'][id='subcheck']").length;
// 获取选中的subcheck的个数
var checkedsub = $("input[type='checkbox'][id='subcheck']:checked").length;
if (checkedsub == chsub) {
// 控制全选按钮的选中
$("#checkboxall").attr("checked", true);
}
}
function funcCheckAll() {
// 判断全选按钮是否是已选中状态
// $("#checkboxall").prop("checked")说明已选中
// JQuery版本不同,if条件不同
if ($("#checkboxall").prop("checked")) {
// 将各个子单选按钮设为选中状态
$('input[name=ids]').attr('checked', 'checked');
} else { // 此时全选按钮起到反选作用
// 将选中状态改为非选中
$('input[name=ids]').removeAttr('checked');
}
// 将'全不选'按钮置为非选中状态
$('input[name=checkboxNotall]').removeAttr('checked');
// 将'反选'按钮置为非选中状态
$('input[name=checkboxInverse]').removeAttr('checked');
}
function funcCheckNotAll() {
// 将选中状态改为非选中
$('input[name=ids]').removeAttr('checked');
// 将'全选'按钮置为非选中状态
$('input[name=checkboxbutton]').removeAttr('checked');
// 将'反选'按钮置为非选中状态
$('input[name=checkboxInverse]').removeAttr('checked');
}
function funcCheckInverse() {
// 将'全选'按钮置为非选中状态
$('input[name=checkboxbutton]').removeAttr('checked');
// 将'全不选'按钮置为非选中状态
$('input[name=checkboxNotall]').removeAttr('checked');
// 获取所有子选框
var checkDelete = document.getElementsByName("ids");
for(var i=0; i<checkDelete.length; i++) {
// 判断全选按钮是否是已选中状态
if (checkDelete[i].type == "checkbox" && checkDelete[i].checked) {
// 将子选框设为非选中状态
checkDelete[i].checked = false;
} else {
// 将子选框设为选中状态
checkDelete[i].checked = true;
}
}
}
上一篇:搭建高性能计算环境(二)、远程登录Linux服务器


下一篇:调整JVM虚拟机的内存大小