checkbox_count.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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-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. },
  23. data: {
  24. simpleData: {
  25. enable: true
  26. }
  27. },
  28. callback: {
  29. onCheck: onCheck
  30. }
  31. };
  32. var zNodes =[
  33. { id:1, pId:0, name:"随意勾选 1", open:true},
  34. { id:11, pId:1, name:"随意勾选 1-1"},
  35. { id:12, pId:1, name:"随意勾选 1-2", open:true},
  36. { id:121, pId:12, name:"随意勾选 1-2-1", checked:true},
  37. { id:122, pId:12, name:"随意勾选 1-2-2"},
  38. { id:123, pId:12, name:"随意勾选 1-2-3"},
  39. { id:13, pId:1, name:"随意勾选 1-3"},
  40. { id:2, pId:0, name:"随意勾选 2", open:true},
  41. { id:21, pId:2, name:"随意勾选 2-1"},
  42. { id:22, pId:2, name:"随意勾选 2-2", open:true},
  43. { id:221, pId:22, name:"随意勾选 2-2-1", checked:true},
  44. { id:222, pId:22, name:"随意勾选 2-2-2"},
  45. { id:223, pId:22, name:"随意勾选 2-2-3"},
  46. { id:23, pId:2, name:"随意勾选 2-3", checked:true}
  47. ];
  48. var clearFlag = false;
  49. function onCheck(e, treeId, treeNode) {
  50. count();
  51. if (clearFlag) {
  52. clearCheckedOldNodes();
  53. }
  54. }
  55. function clearCheckedOldNodes() {
  56. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  57. nodes = zTree.getChangeCheckedNodes();
  58. for (var i=0, l=nodes.length; i<l; i++) {
  59. nodes[i].checkedOld = nodes[i].checked;
  60. }
  61. }
  62. function count() {
  63. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  64. checkCount = zTree.getCheckedNodes(true).length,
  65. nocheckCount = zTree.getCheckedNodes(false).length,
  66. changeCount = zTree.getChangeCheckedNodes().length;
  67. $("#checkCount").text(checkCount);
  68. $("#nocheckCount").text(nocheckCount);
  69. $("#changeCount").text(changeCount);
  70. }
  71. function createTree() {
  72. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  73. count();
  74. clearFlag = $("#last").attr("checked");
  75. }
  76. $(document).ready(function(){
  77. createTree();
  78. $("#init").bind("change", createTree);
  79. $("#last").bind("change", createTree);
  80. });
  81. //-->
  82. </SCRIPT>
  83. </HEAD>
  84. <BODY>
  85. <h1>checkbox 勾选统计</h1>
  86. <h6>[ 文件路径: excheck/checkbox_count.html ]</h6>
  87. <div class="content_wrap">
  88. <div class="zTreeDemoBackground left">
  89. <ul id="treeDemo" class="ztree"></ul>
  90. </div>
  91. <div class="right">
  92. <ul class="info">
  93. <li class="title"><h2>1、getChangeCheckedNodes / getCheckedNodes 方法操作说明</h2>
  94. <ul class="list">
  95. <li class="highlight_red">使用 zTreeObj.getChangeCheckedNodes / getCheckedNodes 方法,详细请参见 API 文档中的相关内容</li>
  96. <li><p>去勾选 checkbox 比较下面的数字变化:<br/>
  97. <ul id="log" class="log" style="height:110px;">
  98. <li>当前被勾选的节点共 <span id="checkCount" class="highlight_red"></span> 个</li>
  99. <li>当前未被勾选的节点共 <span id="nocheckCount" class="highlight_red"></span> 个</li>
  100. <li>勾选状态对比规则:<input type="radio" id="init" name="stateType" class="radio first" checked /><span>与 zTree 初始化时对比</span><br/>
  101. <input type="radio" id="last" name="stateType" class="radio first" style="margin-left:108px;"/><span>与上一次勾选后对比</span></li>
  102. <li>当前被修改勾选状态的节点共 <span id="changeCount" class="highlight_red"></span> 个</li>
  103. </ul></p>
  104. </li>
  105. </ul>
  106. </li>
  107. <li class="title"><h2>2、setting 配置信息说明</h2>
  108. <ul class="list">
  109. <li>同 "checkbox 勾选操作" 中的说明</li>
  110. </ul>
  111. </li>
  112. <li class="title"><h2>3、treeNode 节点数据说明</h2>
  113. <ul class="list">
  114. <li>同 "checkbox 勾选操作" 中的说明</li>
  115. </ul>
  116. </li>
  117. </ul>
  118. </div>
  119. </div>
  120. </BODY>
  121. </HTML>