我是靠谱客的博主 贪玩西装,这篇文章主要介绍使用jQuery+EasyUI实现CheckBoxTree的级联选中特效,现在分享给大家,希望可以做个参考。

需求:子结点选中,父节点随之选中,父节点取消,子节点随之取消

代码:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="js/themes/default/easyui.css" rel="stylesheet" /> <link href="js/themes/icon.css" rel="stylesheet" /> <script src="js/jquery-1.8.0.min.js"></script> <script src="js/jquery.easyui.min.js"></script> <script src="js/locale/easyui-lang-zh_CN.js"></script> <script type="text/javascript"> var data = [{ "id": 1, "text": "系统", "children": [{ "id": 11, "text": "用户管理", "children": [{ "id": 19, "text": "增加" }, { "id": 3, "text": "修改" }, { "id": 5, "text": "删除" }] }, { "id": 12, "text": "角色管理", "children": [{ "id": 13, "text": "增加" }, { "id": 3, "text": "修改" }, { "id": 5, "text": "删除" }] }] }, { "id": 2, "text": "其他", "state": "closed" }]; $(function () { $("#tt").tree({ data: data, checkbox: true, cascadeCheck: false, onCheck: function (node, checked) { if (checked) { var parentNode = $("#tt").tree('getParent', node.target); if (parentNode != null) { $("#tt").tree('check', parentNode.target); } } else { var childNode = $("#tt").tree('getChildren', node.target); if (childNode.length > 0) { for (var i = 0; i < childNode.length; i++) { $("#tt").tree('uncheck', childNode[i].target); } } } } }); }); function getChecked() { var arr = []; var checkeds = $('#tt').tree('getChecked', 'checked'); for (var i = 0; i < checkeds.length; i++) { arr.push(checkeds[i].id); } alert(arr.join(',')); } </script> </head> <body> <ul id="tt"></ul> <input type="button" value="获取选中" onclick="getChecked()" /> </body> </html>

如图:

最后

以上就是贪玩西装最近收集整理的关于使用jQuery+EasyUI实现CheckBoxTree的级联选中特效的全部内容,更多相关使用jQuery+EasyUI实现CheckBoxTree内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部