select_menu_radio.html 3.9 KB

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