标签:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Ztree</title> <link href="zTreeStyle.css" rel="stylesheet" /> <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript" src="jquery.ztree.all-3.5.min.js"></script> <script type="text/javascript"> var zNodes = [{"Id":0,"Pid":-1,"Name":"网来平台"},{"Id":1,"Pid":0,"Name":"模块1"},{"Id":6,"Pid":1,"Name":"模块1-功能1"},{"Id":7,"Pid":1,"Name":"模块1-功能2"},{"Id":8,"Pid":1,"Name":"模块1-功能3"},{"Id":9,"Pid":1,"Name":"模块1-功能4"},{"Id":10,"Pid":1,"Name":"模块1-功能5"},{"Id":2,"Pid":0,"Name":"模块2"},{"Id":11,"Pid":2,"Name":"模块2-功能1"},{"Id":12,"Pid":2,"Name":"模块2-功能2"},{"Id":13,"Pid":2,"Name":"模块2-功能3"},{"Id":14,"Pid":2,"Name":"模块2-功能4"},{"Id":15,"Pid":2,"Name":"模块2-功能5"},{"Id":3,"Pid":0,"Name":"模块3"},{"Id":16,"Pid":3,"Name":"模块3-功能1"},{"Id":17,"Pid":3,"Name":"模块3-功能2"},{"Id":18,"Pid":3,"Name":"模块3-功能3"},{"Id":19,"Pid":3,"Name":"模块3-功能4"},{"Id":20,"Pid":3,"Name":"模块3-功能5"},{"Id":4,"Pid":0,"Name":"模块4"},{"Id":21,"Pid":4,"Name":"模块4-功能1"},{"Id":22,"Pid":4,"Name":"模块4-功能2"},{"Id":23,"Pid":4,"Name":"模块4-功能3"},{"Id":24,"Pid":4,"Name":"模块4-功能4"},{"Id":25,"Pid":4,"Name":"模块4-功能5"},{"Id":5,"Pid":0,"Name":"模块5"},{"Id":26,"Pid":5,"Name":"模块5-功能1"},{"Id":27,"Pid":5,"Name":"模块5-功能2"},{"Id":28,"Pid":5,"Name":"模块5-功能3"},{"Id":29,"Pid":5,"Name":"模块5-功能4"},{"Id":30,"Pid":5,"Name":"模块5-功能5"}]; var setting = { check: { enable: true }, data: {//数据加载 keep: { parent: true, leaf: true }, simpleData: { enable: true, idKey: "Id", pIdKey: "Pid" }, key: { name: "Name" } } }; $(function () { $.fn.zTree.init($("#powerTree"), setting, zNodes); }); jQuery().ready(function () { $("#btnTest").click(function () { var treeObj = $.fn.zTree.getZTreeObj("powerTree"); var nodes = treeObj.getCheckedNodes(true); var checkNodes = []; var txt = ""; for (var i = 0; i < nodes.length; i++) { if (nodes[i].isParent) { //判断是否是父节点 txt.replace(nodes[i].Name, ""); } else { txt += nodes[i].Name + ","; checkNodes.push(nodes[i]); } } alert(txt); var strCheckNodes = JSON.stringify(checkNodes); }); }); </script> </head> <body> <div> <ul id="powerTree" class="ztree"> </ul> </div> <input type="button" name="btnTest" id="btnTest" value="测试节点" /> </body> </html>
标签:
原文地址:http://www.cnblogs.com/ZJ199012/p/4506243.html