radio_fun.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - beforeCheck / onCheck</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. <!--
  12. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
  13. -->
  14. <SCRIPT type="text/javascript">
  15. <!--
  16. var setting = {
  17. view: {
  18. selectedMulti: false
  19. },
  20. check: {
  21. enable: true,
  22. chkStyle: "radio",
  23. radioType: "level"
  24. },
  25. data: {
  26. simpleData: {
  27. enable: true
  28. }
  29. },
  30. callback: {
  31. beforeCheck: beforeCheck,
  32. onCheck: onCheck
  33. }
  34. };
  35. var zNodes =[
  36. { id:1, pId:0, name:"随意勾选 1", open:true},
  37. { id:11, pId:1, name:"无 radio 1-1", nocheck:true},
  38. { id:12, pId:1, name:"随意勾选 1-2", open:true},
  39. { id:121, pId:12, name:"随意勾选 1-2-1"},
  40. { id:122, pId:12, name:"随意勾选 1-2-2"},
  41. { id:123, pId:12, name:"无 radio 1-2-3", nocheck:true},
  42. { id:13, pId:1, name:"随意勾选 1-3"},
  43. { id:2, pId:0, name:"禁止勾选 2", open:true, doCheck:false},
  44. { id:21, pId:2, name:"禁止勾选 2-1", doCheck:false},
  45. { id:22, pId:2, name:"禁止勾选 2-2", checked:true, open:true, doCheck:false},
  46. { id:221, pId:22, name:"禁止勾选 2-2-1", doCheck:false},
  47. { id:222, pId:22, name:"禁止勾选 2-2-2", checked:true, doCheck:false},
  48. { id:223, pId:22, name:"禁止勾选 2-2-3", doCheck:false},
  49. { id:23, pId:2, name:"禁止勾选 2-3", doCheck:false}
  50. ];
  51. var code, log, className = "dark";
  52. function beforeCheck(treeId, treeNode) {
  53. className = (className === "dark" ? "":"dark");
  54. showLog("[ "+getTime()+" beforeCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
  55. return (treeNode.doCheck !== false);
  56. }
  57. function onCheck(e, treeId, treeNode) {
  58. showLog("[ "+getTime()+" onCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
  59. }
  60. function showLog(str) {
  61. if (!log) log = $("#log");
  62. log.append("<li class='"+className+"'>"+str+"</li>");
  63. if(log.children("li").length > 6) {
  64. log.get(0).removeChild(log.children("li")[0]);
  65. }
  66. }
  67. function getTime() {
  68. var now= new Date(),
  69. h=now.getHours(),
  70. m=now.getMinutes(),
  71. s=now.getSeconds(),
  72. ms=now.getMilliseconds();
  73. return (h+":"+m+":"+s+ " " +ms);
  74. }
  75. function checkNode(e) {
  76. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  77. type = e.data.type,
  78. nodes = zTree.getSelectedNodes();
  79. if (type.indexOf("All")<0 && nodes.length == 0) {
  80. alert("请先选择一个节点");
  81. }
  82. if (type == "checkAllTrue") {
  83. zTree.checkAllNodes(true);
  84. } else if (type == "checkAllFalse") {
  85. zTree.checkAllNodes(false);
  86. } else {
  87. var callbackFlag = $("#callbackTrigger").attr("checked");
  88. for (var i=0, l=nodes.length; i<l; i++) {
  89. if (type == "checkTrue") {
  90. zTree.checkNode(nodes[i], true, null, callbackFlag);
  91. } else if (type == "checkFalse") {
  92. zTree.checkNode(nodes[i], false, null, callbackFlag);
  93. }else if (type == "checkTruePS") {
  94. zTree.checkNode(nodes[i], true, true, callbackFlag);
  95. } else if (type == "checkFalsePS") {
  96. zTree.checkNode(nodes[i], false, true, callbackFlag);
  97. }
  98. }
  99. }
  100. }
  101. $(document).ready(function(){
  102. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  103. $("#checkTrue").bind("click", {type:"checkTrue"}, checkNode);
  104. $("#checkFalse").bind("click", {type:"checkFalse"}, checkNode);
  105. });
  106. //-->
  107. </SCRIPT>
  108. </HEAD>
  109. <BODY>
  110. <h1>用 zTree 方法 勾选 radio</h1>
  111. <h6>[ 文件路径: excheck/radio_fun.html ]</h6>
  112. <div class="content_wrap">
  113. <div class="zTreeDemoBackground left">
  114. <ul id="treeDemo" class="ztree"></ul>
  115. </div>
  116. <div class="right">
  117. <ul class="info">
  118. <li class="title"><h2>1、beforeCheck / onCheck 事件回调函数控制</h2>
  119. <ul class="list">
  120. <li>利用 beforeCheck / onCheck 事件回调函数 可以控制是否允许 更改 节点勾选状态,这里简单演示如何监控此事件</li>
  121. <li><p>试试看:<br/>
  122. &nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="callbackTrigger" checked /> checkNode 方法是否触发 callback<br/>
  123. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="checkTrue" href="#" title="不想勾选我就不勾选你..." onclick="return false;">勾选</a> ]
  124. &nbsp;&nbsp;&nbsp;&nbsp;[ <a id="checkFalse" href="#" title="不想取消勾选我就不取消你..." onclick="return false;">取消勾选</a> ]</p>
  125. <li><p><span class="highlight_red">使用 zTreeObj.checkNode 方法,详细请参见 API 文档中的相关内容</span><br/>
  126. beforeCheck / onCheck log:<br/>
  127. <ul id="log" class="log" style="height:130px;"></ul></p>
  128. </li>
  129. </ul>
  130. </li>
  131. <li class="title"><h2>2、setting 配置信息说明</h2>
  132. <ul class="list">
  133. <li>同 "radio 勾选操作" 中的说明</li>
  134. </ul>
  135. </li>
  136. <li class="title"><h2>3、treeNode 节点数据说明</h2>
  137. <ul class="list">
  138. <li>同 "radio 勾选操作" 中的说明</li>
  139. </ul>
  140. </li>
  141. </ul>
  142. </div>
  143. </div>
  144. </BODY>
  145. </HTML>