select_menu_checkbox.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - checkbox select menu</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 setting = {
  15. check: {
  16. enable: true,
  17. chkboxType: {"Y":"", "N":""}
  18. },
  19. view: {
  20. dblClickExpand: false
  21. },
  22. data: {
  23. simpleData: {
  24. enable: true
  25. }
  26. },
  27. callback: {
  28. beforeClick: beforeClick,
  29. onCheck: onCheck
  30. }
  31. };
  32. var zNodes =[
  33. {id:1, pId:0, name:"Beijing"},
  34. {id:2, pId:0, name:"Tianjin"},
  35. {id:3, pId:0, name:"Shanghai"},
  36. {id:6, pId:0, name:"Chongqing"},
  37. {id:4, pId:0, name:"Hebei Province", open:true},
  38. {id:41, pId:4, name:"Shijiazhuang"},
  39. {id:42, pId:4, name:"Baoding"},
  40. {id:43, pId:4, name:"Handan"},
  41. {id:44, pId:4, name:"Chengde"},
  42. {id:5, pId:0, name:"Guangdong Province", open:true},
  43. {id:51, pId:5, name:"Guangzhou"},
  44. {id:52, pId:5, name:"Shenzhen"},
  45. {id:53, pId:5, name:"Dongguan"},
  46. {id:54, pId:5, name:"Fushan"},
  47. {id:6, pId:0, name:"Fujian Province", open:true},
  48. {id:61, pId:6, name:"Fuzhou"},
  49. {id:62, pId:6, name:"Xiamen"},
  50. {id:63, pId:6, name:"Quanzhou"},
  51. {id:64, pId:6, name:"Sanming"}
  52. ];
  53. function beforeClick(treeId, treeNode) {
  54. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  55. zTree.checkNode(treeNode, !treeNode.checked, null, true);
  56. return false;
  57. }
  58. function onCheck(e, treeId, treeNode) {
  59. var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
  60. nodes = zTree.getCheckedNodes(true),
  61. v = "";
  62. for (var i=0, l=nodes.length; i<l; i++) {
  63. v += nodes[i].name + ",";
  64. }
  65. if (v.length > 0 ) v = v.substring(0, v.length-1);
  66. var cityObj = $("#citySel");
  67. cityObj.attr("value", v);
  68. }
  69. function showMenu() {
  70. var cityObj = $("#citySel");
  71. var cityOffset = $("#citySel").offset();
  72. $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
  73. $("body").bind("mousedown", onBodyDown);
  74. }
  75. function hideMenu() {
  76. $("#menuContent").fadeOut("fast");
  77. $("body").unbind("mousedown", onBodyDown);
  78. }
  79. function onBodyDown(event) {
  80. if (!(event.target.id == "menuBtn" || event.target.id == "citySel" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
  81. hideMenu();
  82. }
  83. }
  84. $(document).ready(function(){
  85. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  86. });
  87. //-->
  88. </SCRIPT>
  89. <style type="text/css">
  90. </style>
  91. </HEAD>
  92. <BODY>
  93. <h1>Drop-down Menu with checkbox</h1>
  94. <h6>[ File Path: super/select_menu_checkbox.html ]</h6>
  95. <div class="content_wrap">
  96. <div class="zTreeDemoBackground left">
  97. <ul class="list">
  98. <li class="title">&nbsp;&nbsp;<span class="highlight_red">Check the checkbox to select or click the node</span></li>
  99. <li class="title">&nbsp;&nbsp;Test: <input id="citySel" type="text" readonly value="" style="width:120px;" onclick="showMenu();" />
  100. &nbsp;<a id="menuBtn" href="#" onclick="showMenu(); return false;">select</a></li>
  101. </ul>
  102. </div>
  103. <div class="right">
  104. <ul class="info">
  105. <li class="title"><h2>Explanation of implementation method</h2>
  106. <ul class="list">
  107. <li>You can achieve multi-selected drop-down menu with checkbox.</li>
  108. <li>This Demo is mainly used for compare with other drop-down menu.</li>
  109. </ul>
  110. </li>
  111. </ul>
  112. </div>
  113. </div>
  114. <div id="menuContent" class="menuContent" style="display:none; position: absolute;">
  115. <ul id="treeDemo" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
  116. </div>
  117. </BODY>
  118. </HTML>