一个页面多个全选,根据父节点来实现
来源:互联网 发布:公寓租房软件 编辑:程序博客网 时间:2024/04/30 21:20
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>jQuery实现CheckBox全选、全不选</title>
<script src="js/jquery-1.11.1.js" type="text/javascript"></script>
<script type="text/javascript">
(function($) {
$.fn.checkboxAll = function(a, b, c) {
//a表示全选name值,b表示子checkbox的name值
var $select_all = $("input[name='" + a + "']");
var $childBox = $("input[name='" + b + "']");
for (var i = 0; i < $select_all.length; i++) {
$select_all[i].onclick = function() {
var checkTure = $(this).prop("checked");
var l = $(this).parent(c).find("input[type='checkbox']").length;
alert(l)
for (var j = 0; j <= l; j++) {
var childAll = $(this).parent(c).find("input[type='checkbox']").eq(j);
if (checkTure) {
childAll.prop("checked", true);
} else {
childAll.prop("checked", false);
}
}
};
}
for (var i = 0; i < $childBox.length; i++) {
$childBox[i].onclick = function() {
var checkTure = $(this).prop("checked");
//判断点击商品选中状态
var childlen = $("input[name='" + b + "']:checked").length;
//判断商家是否选中个数
if (childlen != $childBox.length) {
//判断商家下面的商品是否全部选中
$(this).prop("checked", false);
for (var m = 0; m <= $select_all.length; m++) {
//取消全选样式
var notSelect = $("input[name='" + a + "']").eq(m);
notSelect.prop("checked", false);
}
} else {
//点击商品选中
$(this).prop("checked", true);
var childlen = $("input[name='" + b + "']:checked").length;
//判断商家是否选中个数
if (childlen != $childBox.length) {
//判断卖家是否全部选中
for (var m = 0; m <= $select_all.length; m++) {
var notSelect = $("input[name='" + a + "']").eq(m);
notSelect.prop("checked", false);
}
} else {
for (var m = 0; m <= $select_all.length; m++) {
var notSelect = $("input[name='" + a + "']").eq(m);
notSelect.prop("checked", true);
}
}
}
if (checkTure) {
//控制本身是否选中
$(this).prop("checked", true);
} else {
$(this).prop("checked", false);
}
};
}
};
})(jQuery);
$(function(){
$(".all").checkboxAll("all", "childBox", ".a");
$(".test").checkboxAll("test", "childTest", ".b");
});
</script>
</head>
<body>
<div style="width: 100%;">
<div class="a" style="width: 300px; margin: 100px auto; border: 1px solid #ccc; padding: 20px;">
<input name="all" class="all" type="checkbox" />全选
<br />
<input name="childBox" type="checkbox" />项1
<br />
<input name="childBox" type="checkbox" />项2
<br />
<input name="childBox" type="checkbox" />项3
<br />
<input name="childBox" type="checkbox" />项4
<br />
<input name="all" class="all" type="checkbox" />全选
</div>
<div class="b" style="width: 300px; margin: 100px auto; border: 1px solid #ccc; padding: 20px;">
<input id="checkAll" name="test" class="test" type="checkbox" />全选
<br />
<input name="childTest" type="checkbox" />项1
<br />
<input name="childTest" type="checkbox" />项2
<br />
<input name="childTest" type="checkbox" />项3
<br />
<input name="childTest" type="checkbox" />项4
<br />
<input name="test" class="test" type="checkbox" />全选
</div>
</div>
</body>
</html>
<html>
<head>
<meta charset="UTF-8" />
<title>jQuery实现CheckBox全选、全不选</title>
<script src="js/jquery-1.11.1.js" type="text/javascript"></script>
<script type="text/javascript">
(function($) {
$.fn.checkboxAll = function(a, b, c) {
//a表示全选name值,b表示子checkbox的name值
var $select_all = $("input[name='" + a + "']");
var $childBox = $("input[name='" + b + "']");
for (var i = 0; i < $select_all.length; i++) {
$select_all[i].onclick = function() {
var checkTure = $(this).prop("checked");
var l = $(this).parent(c).find("input[type='checkbox']").length;
alert(l)
for (var j = 0; j <= l; j++) {
var childAll = $(this).parent(c).find("input[type='checkbox']").eq(j);
if (checkTure) {
childAll.prop("checked", true);
} else {
childAll.prop("checked", false);
}
}
};
}
for (var i = 0; i < $childBox.length; i++) {
$childBox[i].onclick = function() {
var checkTure = $(this).prop("checked");
//判断点击商品选中状态
var childlen = $("input[name='" + b + "']:checked").length;
//判断商家是否选中个数
if (childlen != $childBox.length) {
//判断商家下面的商品是否全部选中
$(this).prop("checked", false);
for (var m = 0; m <= $select_all.length; m++) {
//取消全选样式
var notSelect = $("input[name='" + a + "']").eq(m);
notSelect.prop("checked", false);
}
} else {
//点击商品选中
$(this).prop("checked", true);
var childlen = $("input[name='" + b + "']:checked").length;
//判断商家是否选中个数
if (childlen != $childBox.length) {
//判断卖家是否全部选中
for (var m = 0; m <= $select_all.length; m++) {
var notSelect = $("input[name='" + a + "']").eq(m);
notSelect.prop("checked", false);
}
} else {
for (var m = 0; m <= $select_all.length; m++) {
var notSelect = $("input[name='" + a + "']").eq(m);
notSelect.prop("checked", true);
}
}
}
if (checkTure) {
//控制本身是否选中
$(this).prop("checked", true);
} else {
$(this).prop("checked", false);
}
};
}
};
})(jQuery);
$(function(){
$(".all").checkboxAll("all", "childBox", ".a");
$(".test").checkboxAll("test", "childTest", ".b");
});
</script>
</head>
<body>
<div style="width: 100%;">
<div class="a" style="width: 300px; margin: 100px auto; border: 1px solid #ccc; padding: 20px;">
<input name="all" class="all" type="checkbox" />全选
<br />
<input name="childBox" type="checkbox" />项1
<br />
<input name="childBox" type="checkbox" />项2
<br />
<input name="childBox" type="checkbox" />项3
<br />
<input name="childBox" type="checkbox" />项4
<br />
<input name="all" class="all" type="checkbox" />全选
</div>
<div class="b" style="width: 300px; margin: 100px auto; border: 1px solid #ccc; padding: 20px;">
<input id="checkAll" name="test" class="test" type="checkbox" />全选
<br />
<input name="childTest" type="checkbox" />项1
<br />
<input name="childTest" type="checkbox" />项2
<br />
<input name="childTest" type="checkbox" />项3
<br />
<input name="childTest" type="checkbox" />项4
<br />
<input name="test" class="test" type="checkbox" />全选
</div>
</div>
</body>
</html>
0 0
- 一个页面多个全选,根据父节点来实现
- javascript 实现 TreeView全选(实现子节点全选,中父节点自动全选)
- 根据数据库字段来创建一个页面
- TreeView控件实现选中父节点时全选子节点
- TreeView控件实现选中父节点时全选子节点
- TreeView控件实现选中父节点时全选子节点
- 根据css 样式实现全选
- 一个页面实现多个管理页面任意切换
- vue 移动端今天写了一个根据后台传过来的http状态码,来实现跳转error页面
- 工作流中实现一个节点多个节点的顺序审批
- 一个页面里多组多选框的全选
- js +html 同一页面,多个全选 /全不选
- 有一个二叉树,现在怀疑它有一个结点有2个父节点,请写出一个函数来判断该二叉树是否存在一个节点含有2个父节点。如果存在,返回true,否则返回false。
- 有一个二叉树,现在怀疑它有一个结点有2个父节点,请写出一个函数来判断该二叉树是否存在一个节点含有2个父节点。如果存在,返回true,否则返回false。
- 树形多选框,选中/取消父节点子节点全选中/取消,选中一个子节点父节点选中,子节点全取消父节点取消
- dom4j来实现对一个节点元素内容的改变
- android中一个activity实现多个xml页面互换。
- android 一个页面内 多个listview的实现
- could only be replicated to 0 nodes instead of minReplication (=1)
- ubuntu16.04配置Lamp环境(搭建linux+apache+mysql+php7环境
- 字符串查找
- Intel Media SDK
- 如何更好的在dropWizard使用IOC容器
- 一个页面多个全选,根据父节点来实现
- LabVIEW事件结构
- 英特尔 QSV 在 FFMPEG 中的使用(Windows)
- js实现多文件上传
- Java IO : ObjectInputStream、ObjectOutputStream
- jQuery 之 函数回调与连接方法(五)
- android打包
- keepalived配置tomcat主备
- Intel Media SDK 介绍