1、 添加自定義屬性 page 2、 為 ztree 每個樹形節點,添加點擊事件 ...
1、 添加自定義屬性 page
2、 為 ztree 每個樹形節點,添加點擊事件
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>ztree樹形菜單的使用</title> 7 <!-- 導入jquery核心類庫 --> 8 <script type="text/javascript" src="../js/jquery-1.8.3.js"></script> 9 <!-- 導入easyui類庫 --> 10 <link id="easyuiTheme" rel="stylesheet" type="text/css" href="../js/easyui/themes/default/easyui.css"> 11 <link rel="stylesheet" type="text/css" href="../js/easyui/themes/icon.css"> 12 <link rel="stylesheet" type="text/css" href="../css/default.css"> 13 <script type="text/javascript" src="../js/easyui/jquery.easyui.min.js"></script> 14 <!--引入ztree--> 15 <script src="../js/ztree/jquery.ztree.all-3.5.js" type="text/javascript" charset="utf-8"></script> 16 <link rel="stylesheet" type="text/css" href="../js/ztree/zTreeStyle.css" /> 17 18 <script type="text/javascript"> 19 //頁面載入後執行 20 $(function() { 21 //1.進行ztree樹形菜單設置,開啟簡單json數據支持 22 var setting = { 23 data:{ 24 simpleData:{ 25 enable:true//開啟簡單json數據格式支持 26 } 27 }, 28 callback:{ 29 onClick:function(event,treeId,treeNode,clickFlag){ 30 var content = '<div style="width:100%;height:100%;overflow:hidden;">'+'<iframe src="'+treeNode.page+'" scrolling="auto" style="width:100%;height:100%;border:0;"></iframe></div>' 31 //沒有設置page屬性的樹形菜單,不打開選項卡 32 if(treeNode.page!=undefined && treeNode.page!=""){ 33 //如果選項卡已經打開,就選中 34 if($("#mytabs").tabs('exists',treeNode.name)){ 35 //選中選項卡 36 $("#mytabs").tabs('select',treeNode.name); 37 }else{ 38 //如果沒有打開,添加選項卡 39 $("#mytabs").tabs('add',{ 40 title:treeNode.name, 41 content:content, 42 closable:true 43 }); 44 } 45 } 46 } 47 } 48 }; 49 50 //2.提供ztree樹形菜單數據 51 var zNodes = [ 52 {id:1,pId:0,name:"父節點一"}, 53 {id:2,pId:0,name:"父節點二"}, 54 {id:11,pId:1,name:"子節點一"}, 55 {id:12,pId:1,name:"子節點二"}, 56 {id:13,pId:2,name:"CSDN博客",page:"http://blog.csdn.net/a772304419"}, 57 {id:14,pId:2,name:"博客園",page:"http://www.cnblogs.com/niwotaxuexiba/"} 58 ]; 59 60 //3.生成樹形菜單 61 $.fn.zTree.init($("#baseMenu"),setting,zNodes); 62 }); 63 </script> 64 </head> 65 66 <body class="easyui-layout"> 67 <div data-options="region:'north',title:'你我他學習吧-學習Java的好博客!'" style="height:100px"></div> 68 <div data-options="region:'west',title:'菜單導航'" style="width:200px"> 69 <!--摺疊面板--> 70 <div class="easyui-accordion" data-options="fit:true"> 71 <div data-options="title:'基礎菜單'"> 72 <!--通過ztree插件,製作樹形菜單--> 73 <ul id="baseMenu" class="ztree"></ul> 74 </div> 75 <div data-options="title:'系統菜單'">你我他學習吧</div> 76 </div> 77 </div> 78 <div data-options="region:'center',title:'中部區域'"> 79 <!--選項卡面板--> 80 <div id="mytabs" class="easyui-tabs" data-options="fit:true"> 81 <div data-options="title:'選項卡面板一',closable:true">選項卡面板一</div> 82 <div data-options="title:'選項卡面板二',closable:true">選項卡面板二</div> 83 </div> 84 </div> 85 <div data-options="region:'east',title:'東部區域'" style="width:100px"></div> 86 <div data-options="region:'south',title:'南部區域'" style="height:100px"></div> 87 </body> 88 89 </html>