经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » jQuery » 查看文章
jquery多级树形下拉菜单的实例代码
来源:jb51  时间:2019/7/9 10:21:17  对本文有异议

效果图:

使用方法

(1)引入 jQuery 包,下载地址
(2)引入 zTree 包,下载地址
(3)引入 tree-select.js
(4)$("#id").treeSelect(data);

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>TreeSelect</title>
  6. <script type="text/javascript" src="./js/jquery-1.11.0.min.js"></script>
  7. <link rel="stylesheet" type="text/css" href="js/zTree_v3-master/css/zTreeStyle/zTreeStyle.css" rel="external nofollow" />
  8. <script type="text/javascript" src="js/zTree_v3-master/js/jquery.ztree.all.js"></script>
  9. <script type="text/javascript" src="js/tree-select.js"></script>
  10. </head>
  11. <body>
  12. <div>
  13. <input id="ts_input">
  14. </div>
  15. </body>
  16. </html>
  17. <script type="text/javascript">
  18. $(function () {
  19. var data = getData();
  20. $("#ts_input").treeSelect(data);
  21. });
  22. function getData() {
  23. // ajax get data
  24. var data = [
  25. {
  26. "name": "江苏",
  27. "pid": 0,
  28. "id": -1,
  29. // "icon": "images/page.gif"
  30. },
  31. {
  32. "name": "浙江",
  33. "pid": 0,
  34. "id": -2,
  35. // "icon": "images/page.gif"
  36. },
  37. {
  38. "name": "陕西",
  39. "pid": 0,
  40. "id": -3,
  41. // "icon": "images/page.gif"
  42. },
  43. {
  44. "name": "苏州",
  45. "pid": -1,
  46. "id": 1,
  47. // "icon": "images/page.gif"
  48. },
  49. {
  50. "name": "无锡",
  51. "pid": -1,
  52. "id": 2,
  53. // "icon": "images/page.gif"
  54. },
  55. {
  56. "name": "常州",
  57. "pid": -1,
  58. "id": 3,
  59. // "icon": "images/page.gif"
  60. },
  61. {
  62. "name": "杭州",
  63. "pid": -2,
  64. "id": 4,
  65. // "icon": "images/page.gif"
  66. },
  67. {
  68. "name": "宁波",
  69. "pid": -2,
  70. "id": 5,
  71. // "icon": "images/page.gif"
  72. },
  73. {
  74. "name": "西安",
  75. "pid": -3,
  76. "id": 6,
  77. // "icon": "images/page.gif"
  78. },
  79. {
  80. "name": "宝鸡",
  81. "pid": -3,
  82. "id": 7,
  83. // "icon": "images/page.gif"
  84. },
  85. {
  86. "name": "咸阳",
  87. "pid": -3,
  88. "id": -4,
  89. // "icon": "images/page.gif"
  90. },
  91. {
  92. "name": "秦都",
  93. "pid": -4,
  94. "id": 9,
  95. // "icon": "images/page.gif"
  96. },
  97. {
  98. "name": "杨凌",
  99. "pid": -4,
  100. "id": -5,
  101. // "icon": "images/page.gif"
  102. },
  103. {
  104. "name": "树木园",
  105. "pid": -5,
  106. "id": 1,
  107. // "icon": "images/page.gif"
  108. },
  109. {
  110. "name": "渭河",
  111. "pid": -5,
  112. "id": 2,
  113. // "icon": "images/page.gif"
  114. },
  115. ];
  116. return data;
  117. }
  118. </script>

总结

以上所述是小编给大家介绍的jquery多级树形下拉菜单的实例代码 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对w3xue网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号