checkbox_count.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - getChangeCheckedNodes / getCheckedNodes</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.min.js"></script>
  9. <!-- <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>-->
  10. <script type="text/javascript" src="../../../js/jquery.ztree.core.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.excheck.js"></script>
  12. <!--
  13. <script type="text/javascript" src="../../../js/jquery.ztree.exedit.js"></script>
  14. -->
  15. <SCRIPT type="text/javascript">
  16. <!--
  17. var setting = {
  18. view: {
  19. selectedMulti: false
  20. },
  21. check: {
  22. enable: true
  23. },
  24. data: {
  25. simpleData: {
  26. enable: true
  27. }
  28. },
  29. callback: {
  30. onCheck: onCheck
  31. }
  32. };
  33. var zNodes =[
  34. { id:1, pId:0, name:"can check 1", open:true},
  35. { id:11, pId:1, name:"can check 1-1"},
  36. { id:12, pId:1, name:"can check 1-2", open:true},
  37. { id:121, pId:12, name:"can check 1-2-1", checked:true},
  38. { id:122, pId:12, name:"can check 1-2-2"},
  39. { id:123, pId:12, name:"can check 1-2-3"},
  40. { id:13, pId:1, name:"can check 1-3"},
  41. { id:2, pId:0, name:"can check 2", open:true},
  42. { id:21, pId:2, name:"can check 2-1"},
  43. { id:22, pId:2, name:"can check 2-2", open:true},
  44. { id:221, pId:22, name:"can check 2-2-1", checked:true},
  45. { id:222, pId:22, name:"can check 2-2-2"},
  46. { id:223, pId:22, name:"can check 2-2-3"},
  47. { id:23, pId:2, name:"can check 2-3", checked:true}
  48. ];
  49. var clearFlag = false;
  50. function onCheck(e, treeId, treeNode) {
  51. count();
  52. if (clearFlag) {
  53. clearCheckedOldNodes();
  54. }
  55. }
  56. function clearCheckedOldNodes() {
  57. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  58. nodes = zTree.getChangeCheckedNodes();
  59. for (var i=0, l=nodes.length; i<l; i++) {
  60. nodes[i].checkedOld = nodes[i].checked;
  61. }
  62. }
  63. function count() {
  64. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  65. checkCount = zTree.getCheckedNodes(true).length,
  66. nocheckCount = zTree.getCheckedNodes(false).length,
  67. changeCount = zTree.getChangeCheckedNodes().length;
  68. $("#checkCount").text(checkCount);
  69. $("#nocheckCount").text(nocheckCount);
  70. $("#changeCount").text(changeCount);
  71. }
  72. function createTree() {
  73. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  74. count();
  75. clearFlag = $("#last").attr("checked");
  76. }
  77. $(document).ready(function(){
  78. createTree();
  79. $("#init").bind("change", createTree);
  80. $("#last").bind("change", createTree);
  81. });
  82. //-->
  83. </SCRIPT>
  84. </HEAD>
  85. <BODY>
  86. <h1>Statistics Checkbox is Checked</h1>
  87. <h6>[ File Path: excheck/checkbox_count.html ]</h6>
  88. <div class="content_wrap">
  89. <div class="zTreeDemoBackground left">
  90. <ul id="treeDemo" class="ztree"></ul>
  91. </div>
  92. <div class="right">
  93. <ul class="info">
  94. <li class="title"><h2>1, Explanation of getChangeCheckedNodes / getCheckedNodes</h2>
  95. <ul class="list">
  96. <li class="highlight_red">How to use zTreeObj.getChangeCheckedNodes / getCheckedNodes method, please see the API documentation.</li>
  97. <li><p>Check the checkbox, observe the number of changes:<br/>
  98. <ul id="log" class="log" style="height:130px;">
  99. <li>Total check node: <span id="checkCount" class="highlight_red"></span></li>
  100. <li>Total uncheck node: <span id="nocheckCount" class="highlight_red"></span></li>
  101. <li>Modify the state of checkbox: <br/>
  102. <input type="radio" id="init" name="stateType" class="radio first" checked style="margin-left:68px;"/><span>Compared with zTree initialization</span><br/>
  103. <input type="radio" id="last" name="stateType" class="radio first" style="margin-left:68px;"/><span>Compared with the last check</span></li>
  104. <li>Total change the checkbox state of node: <span id="changeCount" class="highlight_red"></span></li>
  105. </ul></p>
  106. </li>
  107. </ul>
  108. </li>
  109. <li class="title"><h2>2, Explanation of setting</h2>
  110. <ul class="list">
  111. <li>Same as 'Checkbox Operation'</li>
  112. </ul>
  113. </li>
  114. <li class="title"><h2>3, Explanation of treeNode</h2>
  115. <ul class="list">
  116. <li>Same as 'Checkbox Operation'</li>
  117. </ul>
  118. </li>
  119. </ul>
  120. </div>
  121. </div>
  122. </BODY>
  123. </HTML>