树checkbox选择jquery实例
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://my.csdn.net/assets2/js/libs/jquery-1.9.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("input[type='checkbox']").click(function () {
var myid = $(this).attr("id");
//alert(myid);
var isSel = $(this).is(":checked");
selectChkbox(0, myid, isSel);
selectParentChkbox($(this));
});
});
//变更子节点
function selectChkbox(n,parentid, isSel) {
var len = $("input[type='checkbox']").length;
for (var i = n; i < len; i++) {
var inp = $("input[type='checkbox']").eq(i);
var pid = inp.attr("data-parent");
if (parentid == pid) {
if (isSel) {
inp.prop("checked", true);
} else {
inp.prop("checked", false);
}
selectChkbox(i, inp.attr("id"), isSel);
}
}
}
//变更父节点
function selectParentChkbox(clickINP) {
var parentid = clickINP.attr("data-parent");
if (parentid != "null") {
if (!clickINP.is(":checked")) {
selectParentChkF(parentid);
} else {
selectParentChkT(parentid);
}
} }
function selectParentChkF(parentid) {
$("#" + parentid).prop("checked", false);
parentid = $("#" + parentid).attr("data-parent");
if (parentid != "null")
selectParentChkF(parentid);
}
function selectParentChkT(parentid) {
var parentSel = true;
$("input[type='checkbox']").each(function () {
var pid = $(this).attr("data-parent");
if (parentid == pid) {
if (!$(this).is(":checked")) {
parentSel = false;
}
}
});
if (parentSel) {
$("#" + parentid).prop("checked", true);
parentid = $("#" + parentid).attr("data-parent");
if (parentid != "null")
selectParentChkT(parentid);
} else {
selectParentChkF(parentid);
}
}
</script>
</head> <body>
<div>
<div>A<input id="A" data-parent="null" type="checkbox" /></div>
<div style=" margin-left:16px;">B<input id="B" data-parent="A" type="checkbox" /></div>
<div style=" margin-left:32px;">B-1<input id="B-1" data-parent="B" type="checkbox" /></div>
<div style=" margin-left:32px;">B-2<input id="B-2" data-parent="B" type="checkbox" /></div>
<div style=" margin-left:48px;">B-2-1<input id="B-2-1" data-parent="B-2" type="checkbox" /></div>
<div style=" margin-left:48px;">B-2-2<input id="B-2-2" data-parent="B-2" type="checkbox" /></div>
<div style=" margin-left:16px;">C<input id="C" data-parent="A" type="checkbox" /></div>
<div style=" margin-left:32px;">D<input id="D" data-parent="C" type="checkbox" /></div>
<div style=" margin-left:32px;">E<input id="E" data-parent="C" type="checkbox" /></div>
</div>
</body>
</html>
树checkbox选择jquery实例的更多相关文章
- 转:zTree树控件入门之checkbox:如何动态设置节点的checkbox选择框启用与禁用状态(chkDisabled)
当一棵树的部分节点根据登入用户角色不同而决定是否启用节点前的checkbox选择框的时候,我们应该如何做呢?也或者如何在页面加载的时候动态根据当前登入用户角色动态切换节点前的checkbox的禁用状态 ...
- checkbox全选,反选,取消选择 jquery
checkbox全选,反选,取消选择 jquery. //checkbox全部选择 $(":checkbox[name='osfipin']").each(function(){ ...
- 基础 jQuery 实例
基础 jQuery 实例 jQuery 原则: 由于 jQuery 是为处理 HTML 事件而特别设计的,那么当您遵循以下原则时,您的代码会更恰当且更易维护: 把所有 jQuery 代码置于事件处理函 ...
- 值得 Web 开发人员学习的20个 jQuery 实例教程
这篇文章挑选了20个优秀的 jQuery 实例教程,这些 jQuery 教程将帮助你把你的网站提升到一个更高的水平.其中,既有网站中常用功能的的解决方案,也有极具吸引力的亮点功能的实现方法,相信通过对 ...
- jQuery实例——jQuery实现联动下拉列表查询框--转http://www.cnblogs.com/picaso/archive/2012/04/08/2437442.html#undefined
jQuery实例--jQuery实现联动下拉列表查询框 在查询与列表显示的时候经常用到联动列表显示,比如一级选项是国家,二级选项是省,三级是市,这样的联动是联系的实时导出的,比如你不可能选择了四川 ...
- cocos2dx2.2.2登录场景中Checkbox选择框的实现
在前两篇文章中,我们介绍了在注册场景中需要用到的输入框及弹出框的实现方式,这两篇文章中介绍的内容在登录场景同样会用到.而我们经常会在登录场景中见到的另一种元素就是自动登录或者记住密码的Checkbox ...
- jQuery使用(十一):jQuery实例遍历与索引
each() children() index() 一.jQuery实例遍历方法each() jQuery实例上的each()方法规定要运行的函数,并且给函数传入两个参数:index,element. ...
- 三种动态加载js的jquery实例代码另附去除js方法
!-- 这里为你提供了三种动态加载js的jquery实例代码哦,由于jquery是为用户提供方便的,所以利用jquery动态加载文件只要一句话$.getscript("test.js&quo ...
- JQuery中_Radio、DropDownList、Checkbox选择控件的处理
Radio 1.获取选中值,三种方法都可以: $('input:radio:checked').val(): $("input[type='radio']:checked").v ...
随机推荐
- charset=iso-8859-1
今天群里有人在问, 求解:charset="ISO-8859-1"是什么意思 其实我也不大懂,然后就去翻阅了下资料.科普开始: 网页制作中遇到的编码,乱码问题之一:charset= ...
- 11.Find All Numbers Disappeared in an Array(找出数组中缺失的数)
Level: Easy 题目描述: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements ...
- nginx的配置文件(反向代理和主配置)
配置文件保存,是为了工作方便.特别是优化好的配置.我们基本可以直接复制粘贴.这样做可以快速的完成手上的工作!! vim nginx.conf user nginx; worker_processes ...
- zookeeper客户端使用第三方(zkclient)封装的Api操作节点
1.引入依赖 <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</a ...
- java的MAP接口方法
常用操作说明 void clear() 从此映射中移除所有映射关系(可选操作). boolean containsKey(Object key) 如果此映射包含指定键的映射关系,则返回 true. b ...
- LUNA16数据集的百度云链接
可能需要会员链接:https://pan.baidu.com/s/1KTjoGKfLB_1Y-BQzerhGgg 提取码:g901
- javascript 获取当前 URL 参数的两种方法
window.location.host; //返回url 的主机部分,例如:www.xxx.com window.location.hostname; //返回www.xxx.com window. ...
- 洛谷1026(字符串dp)
常规dp.看到数据很小就直接暴力了,没有预处理.kmp好像过分了-- #include <cstdio> #include <cstring> #include <ios ...
- gym 101889I Imperial roads 最小生成树+LCA
题目传送门 题意: 给出一幅无向带权图,q次询问,每次询问都求一棵包含给出的边的最小生成树. 思路: 首先求出最小生成树(kruskal),如果查询的边在最小生成树上,肯定是直接输出最小生成树,如果不 ...
- Educational Codeforces Round 11 B
Description Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of th ...