diydom.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - addHoverDom / removeHoverDom / addDiyDom</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
  12. <SCRIPT type="text/javascript">
  13. <!--
  14. var IDMark_Switch = "_switch",
  15. IDMark_Icon = "_ico",
  16. IDMark_Span = "_span",
  17. IDMark_Input = "_input",
  18. IDMark_Check = "_check",
  19. IDMark_Edit = "_edit",
  20. IDMark_Remove = "_remove",
  21. IDMark_Ul = "_ul",
  22. IDMark_A = "_a";
  23. var setting = {
  24. view: {
  25. addHoverDom: addHoverDom,
  26. removeHoverDom: removeHoverDom,
  27. addDiyDom: addDiyDom
  28. }
  29. };
  30. var zNodes =[
  31. {id:1, name:"hover事件显示控件", open:true,
  32. children:[
  33. {id:11, name:"按钮1"},
  34. {id:12, name:"按钮2"},
  35. {id:13, name:"下拉框"},
  36. {id:141, name:"文本1"},
  37. {id:142, name:"文本2"},
  38. {id:15, name:"超链接"}
  39. ]},
  40. {id:2, name:"始终显示控件", open:true,
  41. children:[
  42. {id:21, name:"按钮1"},
  43. {id:22, name:"按钮2"},
  44. {id:23, name:"下拉框"},
  45. {id:24, name:"文本"},
  46. {id:25, name:"超链接"}
  47. ]}
  48. ];
  49. function addHoverDom(treeId, treeNode) {
  50. if (treeNode.parentNode && treeNode.parentNode.id!=1) return;
  51. var aObj = $("#" + treeNode.tId + IDMark_A);
  52. if (treeNode.id == 11) {
  53. if ($("#diyBtn_"+treeNode.id).length>0) return;
  54. var editStr = "<span id='diyBtn_space_" +treeNode.id+ "' >&nbsp;</span><span class='button icon03' id='diyBtn_" +treeNode.id+ "' title='"+treeNode.name+"' onfocus='this.blur();'></span>";
  55. aObj.append(editStr);
  56. var btn = $("#diyBtn_"+treeNode.id);
  57. if (btn) btn.bind("click", function(){alert("diy Button for " + treeNode.name);});
  58. } else if (treeNode.id == 12) {
  59. if ($("#diyBtn_"+treeNode.id).length>0) return;
  60. var editStr = "<span class='button icon04' id='diyBtn_" +treeNode.id+ "' title='"+treeNode.name+"' onfocus='this.blur();'></span>";
  61. aObj.after(editStr);
  62. var btn = $("#diyBtn_"+treeNode.id);
  63. if (btn) btn.bind("click", function(){alert("diy Button for " + treeNode.name);});
  64. } else if (treeNode.id == 13) {
  65. if ($("#diyBtn_"+treeNode.id).length>0) return;
  66. var editStr = "<span id='diyBtn_space_" +treeNode.id+ "' >&nbsp;</span><select class='selDemo ' id='diyBtn_" +treeNode.id+ "'><option value=1>1</option><option value=2>2</option><option value=3>3</option></select>";
  67. aObj.after(editStr);
  68. var btn = $("#diyBtn_"+treeNode.id);
  69. if (btn) btn.bind("change", function(){alert("diy Select value="+btn.attr("value")+" for " + treeNode.name);});
  70. } else if (treeNode.id == 141) {
  71. if ($("#diyBtn_"+treeNode.id).length>0) return;
  72. var editStr = "<span class='test' id='diyBtn_" +treeNode.id+ "'>Text Demo...</span>";
  73. aObj.append(editStr);
  74. } else if (treeNode.id == 142) {
  75. if ($("#diyBtn_"+treeNode.id).length>0) return;
  76. var editStr = "<span id='diyBtn_" +treeNode.id+ "'>Text Demo...</span>";
  77. aObj.after(editStr);
  78. } else if (treeNode.id == 15) {
  79. if ($("#diyBtn1_"+treeNode.id).length>0) return;
  80. if ($("#diyBtn2_"+treeNode.id).length>0) return;
  81. var editStr = "<a id='diyBtn1_" +treeNode.id+ "' onclick='alert(1);return false;' style='margin:0 0 0 5px;'>链接1</a>" +
  82. "<a id='diyBtn2_" +treeNode.id+ "' onclick='alert(2);return false;' style='margin:0 0 0 5px;'>链接2</a>";
  83. aObj.append(editStr);
  84. }
  85. }
  86. function removeHoverDom(treeId, treeNode) {
  87. if (treeNode.parentTId && treeNode.getParentNode().id!=1) return;
  88. if (treeNode.id == 15) {
  89. $("#diyBtn1_"+treeNode.id).unbind().remove();
  90. $("#diyBtn2_"+treeNode.id).unbind().remove();
  91. } else {
  92. $("#diyBtn_"+treeNode.id).unbind().remove();
  93. $("#diyBtn_space_" +treeNode.id).unbind().remove();
  94. }
  95. }
  96. function addDiyDom(treeId, treeNode) {
  97. if (treeNode.parentNode && treeNode.parentNode.id!=2) return;
  98. var aObj = $("#" + treeNode.tId + IDMark_A);
  99. if (treeNode.id == 21) {
  100. var editStr = "<span class='demoIcon' id='diyBtn_" +treeNode.id+ "' title='"+treeNode.name+"' onfocus='this.blur();'><span class='button icon01'></span></span>";
  101. aObj.append(editStr);
  102. var btn = $("#diyBtn_"+treeNode.id);
  103. if (btn) btn.bind("click", function(){alert("diy Button for " + treeNode.name);});
  104. } else if (treeNode.id == 22) {
  105. var editStr = "<span class='demoIcon' id='diyBtn_" +treeNode.id+ "' title='"+treeNode.name+"' onfocus='this.blur();'><span class='button icon02'></span></span>";
  106. aObj.after(editStr);
  107. var btn = $("#diyBtn_"+treeNode.id);
  108. if (btn) btn.bind("click", function(){alert("diy Button for " + treeNode.name);});
  109. } else if (treeNode.id == 23) {
  110. var editStr = "<select class='selDemo' id='diyBtn_" +treeNode.id+ "'><option value=1>1</option><option value=2>2</option><option value=3>3</option></select>";
  111. aObj.after(editStr);
  112. var btn = $("#diyBtn_"+treeNode.id);
  113. if (btn) btn.bind("change", function(){alert("diy Select value="+btn.attr("value")+" for " + treeNode.name);});
  114. } else if (treeNode.id == 24) {
  115. var editStr = "<span id='diyBtn_" +treeNode.id+ "'>Text Demo...</span>";
  116. aObj.after(editStr);
  117. } else if (treeNode.id == 25) {
  118. var editStr = "<a id='diyBtn1_" +treeNode.id+ "' onclick='alert(1);return false;'>链接1</a>" +
  119. "<a id='diyBtn2_" +treeNode.id+ "' onclick='alert(2);return false;'>链接2</a>";
  120. aObj.after(editStr);
  121. }
  122. }
  123. $(document).ready(function(){
  124. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  125. });
  126. //-->
  127. </SCRIPT>
  128. <style type="text/css">
  129. .ztree li span.demoIcon{padding:0 2px 0 10px;}
  130. .ztree li span.button.icon01{margin:0; background: url(../../../css/zTreeStyle/img/diy/3.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
  131. .ztree li span.button.icon02{margin:0; background: url(../../../css/zTreeStyle/img/diy/4.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
  132. .ztree li span.button.icon03{margin:0; background: url(../../../css/zTreeStyle/img/diy/5.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
  133. .ztree li span.button.icon04{margin:0; background: url(../../../css/zTreeStyle/img/diy/6.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
  134. .ztree li span.button.icon05{margin:0; background: url(../../../css/zTreeStyle/img/diy/7.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
  135. .ztree li span.button.icon06{margin:0; background: url(../../../css/zTreeStyle/img/diy/8.png) no-repeat scroll 0 0 transparent; vertical-align:top; *vertical-align:middle}
  136. </style>
  137. </HEAD>
  138. <BODY>
  139. <h1>添加自定义控件</h1>
  140. <h6>[ 文件路径: super/diydom.html ]</h6>
  141. <div class="content_wrap">
  142. <div class="zTreeDemoBackground left">
  143. <ul id="treeDemo" class="ztree"></ul>
  144. </div>
  145. <div class="right">
  146. <ul class="info">
  147. <li class="title"><h2>1、实现方法说明</h2>
  148. <ul class="list">
  149. <li>利用 setting.view.addHoverDom / removeHoverDom / addDiyDom 这几个参数的配置可以很容易的实现自定义控件的功能</li>
  150. <li class="highlight_red">添加自定义控件,请务必掌握 zTree 节点对象的命名规则,以保证正常添加 DOM 控件</li>
  151. <li class="highlight_red">如果添加标准的 select / checkbox / radio 等,请注意适当调整 zTree 的布局 css,保证 zTree 能正常显示</li>
  152. </ul>
  153. </li>
  154. <li class="title"><h2>2、setting 配置信息说明</h2>
  155. <ul class="list">
  156. <li>使用 setting.view.addHoverDom / removeHoverDom / addDiyDom 属性,详细请参见 API 文档中的相关内容</li>
  157. </ul>
  158. </li>
  159. <li class="title"><h2>3、treeNode 节点数据说明</h2>
  160. <ul class="list">
  161. <li>对 节点数据 没有特殊要求,用户可以根据自己的需求添加自定义属性</li>
  162. </ul>
  163. </li>
  164. </ul>
  165. </div>
  166. </div>
  167. </BODY>
  168. </HTML>