Jquery树插件zTree实现菜单树

<!DOCTYPE html> <html> <head>   <meta charset="utf-8" />   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">   <title>Title</title>   <link href="https://www.jb51.net/JS/tool/zTree/css/zTreeStyle/zTreeStyle.css" />   <script src="https://www.jb51.net/JS/jquery-1.11.1.min.js"></script>   <script src="https://www.jb51.net/JS/tool/zTree/js/jquery.ztree.core-3.5.js"></script>   <script src="https://www.jb51.net/JS/tool/zTree/js/jquery.ztree.excheck-3.5.js"></script> </head> <body>   <div>     <div>       <ul></ul>     </div>   </div>   <script>     var settingLeft = {       view: {         dblClickExpand: false,//双击节点时,是否自动展开父节点的标识         showLine: false,//是否显示节点之间的连线         showIcon: true,         fontCss: { 'color': 'white', 'font-weight': 'normal' },//字体样式函数         selectedMulti: false //设置是否允许同时选中多个节点       },       check: {         //chkboxType: { "Y": "ps", "N": "ps" },         chkStyle: "checkbox",//复选框类型         enable: false //每个节点上是否显示 CheckBox       },       data: {         simpleData: {//简单数据模式           enable: true,           idKey: "id",           pIdKey: "pId",           rootPId: ""         }       },       callback: {         beforeClick: function (treeId, treeNode) {           zTree = $.fn.zTree.getZTreeObj("menu_tree_vehicle");           if (treeNode.isParent) {             zTree.expandNode(treeNode);//如果是父节点,则展开该节点           } else {             zTree.checkNode(treeNode, !treeNode.checked, true, true);//单击勾选,再次单击取消勾选           }         }//,         // onCheck: onCheck       }     };     $(function () {       //初始化菜单树       var zNodes = [         { id: 0, pId: -1, name: "一级部门", open: true },         { id: 1, pId: 0, name: "二级部门1", open: false },         { id: 2, pId: 1, name: "三级部门1" },         { id: 3, pId: 1, name: "三级部门2" },         { id: 4, pId: 0, name: "二级部门2", open: false },         { id: 5, pId: 4, name: "三级部门3" },         { id: 6, pId: 4, name: "三级部门4", open: false },         { id: 7, pId: 6, name: "四级部门1" },         { id: 8, pId: 6, name: "四级部门2" },         { id: 9, pId: 0, name: "二级部门3" },         { id: 10, pId: 0, name: "二级部门4" }       ];       $.fn.zTree.init($("#menu_tree_left"), settingLeft, zNodes);     });   </script> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwgpfg.html