7d4fa0dd705c41c97eea16a49766d900d731c2ee.svn-base 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5. <title></title>
  6. <!--框架必需start-->
  7. <script type="text/javascript" src="../../libs/js/jquery.js"></script>
  8. <script type="text/javascript" src="../../libs/js/language/cn.js"></script>
  9. <script type="text/javascript" src="../../libs/js/framework.js"></script>
  10. <link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
  11. <link rel="stylesheet" type="text/css" id="skin" prePath="../../"/>
  12. <link rel="stylesheet" type="text/css" id="customSkin"/>
  13. <!--框架必需end-->
  14. <!--树组件start -->
  15. <script type="text/javascript" src="../../libs/js/tree/ztree/ztree.js"></script>
  16. <link href="../../libs/js/tree/ztree/ztree.css" rel="stylesheet" type="text/css"/>
  17. <!--树组件end -->
  18. <style>
  19. .infoBtn{
  20. background-image: url(../../sample_html/tree/list.gif)!important;
  21. background-repeat:no-repeat;
  22. background-position:0% 100%;
  23. width:20px!important;
  24. height:16px;
  25. display:inline-block;
  26. }
  27. .layerBtn{
  28. background-image: url(../../sample_html/tree/layers.gif)!important;
  29. background-repeat:no-repeat;
  30. background-position:0% 100%;
  31. width:20px!important;
  32. height:16px;
  33. cursor:default!important;
  34. display:inline-block;
  35. }
  36. .globeBtn{
  37. background-image: url(../../sample_html/tree/find.gif)!important;
  38. background-repeat:no-repeat;
  39. background-position:100% 0%!important;
  40. width:20px!important;
  41. height:16px;
  42. display:inline-block;
  43. }
  44. .arrowBtn{
  45. background-image: url(../../sample_html/tree/chart.gif)!important;
  46. background-repeat:no-repeat;
  47. background-position:100% 0%!important;
  48. width:20px!important;
  49. height:16px;
  50. display:inline-block;
  51. }
  52. .diydom{
  53. width:300px;
  54. }
  55. .diydom li span{
  56. display:inline-block!important;
  57. float:left;
  58. }
  59. .diydomCon{
  60. width:200px;
  61. height:300px;
  62. border:solid 1px #cccccc;
  63. overflow:auto;
  64. background-color:#ffffff;
  65. }
  66. .hoverWidth{
  67. width:80px;
  68. overflow:hidden;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div class="box1" style="width: 600px;"><div class="box_topcenter"><div class="box_topleft"><div class="box_topright"></div></div></div><div class="box_middlecenter"><div class="box_middleleft"><div class="box_middleright"><div class="boxContent" style="overflow: visible;height:600px;">
  74. 隐藏了自带的图标,使用addDiyDom为树节点前添加图标,来实现可点击。<br/>
  75. 使用addHoverDom实现鼠标移入后出现图标,并且可点击。<br/>
  76. <div class="diydomCon">
  77. <ul id="tree-1" class="ztree diydom"></ul>
  78. </div>
  79. </div></div></div></div><div class="box_bottomcenter"><div class="box_bottomleft"><div class="box_bottomright"></div></div></div></div>
  80. <script type="text/javascript">
  81. var curMenu = null, zTree_Menu = null;
  82. var nodes1 = [
  83. { id:1, parentId:0, name:"图层1",open:"true"},
  84. { id:11, parentId:1, name:"元素1"},
  85. { id:12, parentId:1, name:"元素2"},
  86. { id:13, parentId:1, name:"元素名称很长元素名称很长"},
  87. { id:2, parentId:0, name:"图层2"},
  88. { id:21, parentId:2, name:"元素4"},
  89. { id:22, parentId:2, name:"元素5"},
  90. { id:23, parentId:2, name:"元素6"}
  91. ];
  92. var setting1 = {
  93. view: {
  94. addDiyDom: addDiyDom,
  95. addHoverDom: addHoverDom,
  96. removeHoverDom:removeHoverDom,
  97. selectedMulti: false,
  98. showIcon:false,
  99. showLine: false
  100. },
  101. callback: {
  102. onClick: onNodeClick
  103. }
  104. };
  105. //点击节点时对level0的节点进行样式切换
  106. function initComplete(){
  107. //本地数据源
  108. $.fn.zTree.init($("#tree-1"), setting1, nodes1);
  109. }
  110. function addDiyDom(treeId, treeNode) {
  111. var aObj = $("#" + treeNode.tId + "_a");
  112. aObj.addClass("addWidth");
  113. if ($("#infoBtn_"+treeNode.id).length>0) return;
  114. var editStr
  115. if(treeNode.isParent){
  116. editStr= "<span class='layerBtn' id='parentBtn_" + treeNode.id
  117. + "' onfocus='this.blur();'></span>";
  118. }
  119. else{
  120. editStr= "<span class='infoBtn' id='infoBtn_" + treeNode.id
  121. + "' title='查看信息' onfocus='this.blur();'></span>";
  122. }
  123. aObj.prepend(editStr);
  124. var btn = $("#infoBtn_"+treeNode.id);
  125. if (btn) {
  126. btn.bind("click", function(){
  127. alert("查看信息:" + treeNode.name);
  128. });
  129. }
  130. };
  131. function addHoverDom(treeId, treeNode) {
  132. if (treeNode.isParent||$("#globeBtn_" + treeNode.id).length > 0) return;
  133. var sObj = $("#" + treeNode.tId + "_span");
  134. if(sObj.width()>80){
  135. sObj.addClass("hoverWidth");
  136. }
  137. var addStr = "<span class='globeBtn' id='globeBtn_" + treeNode.id + "' title='周边查找' onfocus='this.blur();'></span>";
  138. sObj.after(addStr);
  139. var addStr2 = "<span class='arrowBtn' id='arrowBtn_" + treeNode.id + "' title='信息统计' onfocus='this.blur();'></span>";
  140. sObj.after(addStr2);
  141. var btn = $("#globeBtn_" + treeNode.id);
  142. if (btn){
  143. btn.bind("click", function(){
  144. alert("周边查找:" + treeNode.name);
  145. });
  146. }
  147. var btn2 = $("#arrowBtn_" + treeNode.id);
  148. if (btn2){
  149. btn2.bind("click", function(){
  150. alert("信息统计:" + treeNode.name);
  151. });
  152. }
  153. };
  154. function removeHoverDom(treeId, treeNode) {
  155. $("#globeBtn_" + treeNode.id).unbind().remove();
  156. $("#arrowBtn_" + treeNode.id).unbind().remove();
  157. var sObj = $("#" + treeNode.tId + "_span");
  158. sObj.removeClass("hoverWidth");
  159. };
  160. function onNodeClick(event, treeId, treeNode){
  161. var zTree = $.fn.zTree.getZTreeObj("tree-1");
  162. zTree.expandNode(treeNode);
  163. }
  164. </script>
  165. </div>
  166. </body>
  167. </html>