zTree插件實現菜單樹


 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4   <meta charset="utf-8" />
 5   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 6   <title>Title</title>
 7   <link href="JS/tool/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" />
 8   <script src="JS/jquery-1.11.1.min.js"></script>
 9   <script src="JS/tool/zTree/js/jquery.ztree.core-3.5.js"></script>
10   <script src="JS/tool/zTree/js/jquery.ztree.excheck-3.5.js"></script>
11 
12 </head>
13 <body style="background: #ddd;">
14   <div class="mainbody-left">
15     <div class="vvtree dept-tree left">
16       <ul id="menu_tree_left" class="ztree"></ul>
17     </div>
18   </div>
19   <script>
20     var settingLeft = {
21       view: {
22         dblClickExpand: false,//雙擊節點時,是否自動展開父節點的標識
23         showLine: false,//是否顯示節點之間的連線
24         showIcon: true,
25         fontCss: { 'color': 'white', 'font-weight': 'normal' },//字體樣式函數
26         selectedMulti: false //設置是否允許同時選中多個節點
27       },
28       check: {
29         //chkboxType: { "Y": "ps", "N": "ps" },
30         chkStyle: "checkbox",//復選框類型
31         enable: false //每個節點上是否顯示 CheckBox
32       },
33       data: {
34         simpleData: {//簡單數據模式
35           enable: true,
36           idKey: "id",
37           pIdKey: "pId",
38           rootPId: ""
39         }
40       },
41       callback: {
42 
43         beforeClick: function (treeId, treeNode) {
44           zTree = $.fn.zTree.getZTreeObj("menu_tree_vehicle");
45           if (treeNode.isParent) {
46             zTree.expandNode(treeNode);//如果是父節點,則展開該節點
47           } else {
48             zTree.checkNode(treeNode, !treeNode.checked, true, true);//單擊勾選,再次單擊取消勾選
49           }
50         }//,
51         // onCheck: onCheck
52 
53       }
54     };
55 
56     $(function () {
57       //初始化菜單樹
58       var zNodes = [
59         { id: 0, pId: -1, name: "一級部門", open: true },
60         { id: 1, pId: 0, name: "二級部門1", open: false },
61         { id: 2, pId: 1, name: "三級部門1" },
62         { id: 3, pId: 1, name: "三級部門2" },
63         { id: 4, pId: 0, name: "二級部門2", open: false },
64         { id: 5, pId: 4, name: "三級部門3" },
65         { id: 6, pId: 4, name: "三級部門4", open: false },
66         { id: 7, pId: 6, name: "四級部門1" },
67         { id: 8, pId: 6, name: "四級部門2" },
68         { id: 9, pId: 0, name: "二級部門3" },
69         { id: 10, pId: 0, name: "二級部門4" }
70       ];
71       $.fn.zTree.init($("#menu_tree_left"), settingLeft, zNodes);
72     });
73   </script>
74 </body>
75 
76 </html>

完成!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM