最近一个项目 需要用到jstree 这个jQuery插件,就研究了下,做目录树 菜单还是很强大的,下面对经常会用到几个用法做下说明。

1. 首先页面 引用 jquery.jstree

2. html :

  1. <div id="cate_tree" class="jstree fl">
  2. <ul>
  3. <li id="0" class="jstree-closed jstree-unchecked">
  4. <a href="#" class="jstree-clicked">
  5. <ins class="jstree-checkbox"> </ins>
  6. All Product
  7. </a>
  8. <ul style="">
  9. {foreach $categories as $cat}
  10. <li id="{$cat.id}" class="jstree-closed jstree-unchecked">
  11. <a href="#" class="jstree-clicked">
  12. <ins class="jstree-checkbox"> </ins>
  13. {$cat.name}
  14. </a>
  15. {if $cat.sub|@count > 0}
  16. <ul style="">
  17. {foreach $cat.sub as $subcat}
  18. <li id="{$subcat.id}" class="jstree-leaf jstree-unchecked">
  19. <a href="#" class="">
  20. <ins class="jstree-checkbox"> </ins>
  21. {$subcat.name}
  22. </a>
  23. </li>
  24. {/foreach}
  25. </ul>
  26. {/if}
  27. </li>
  28. {/foreach}
  29. </ul>
  30. </li>
  31. </ul>
  32. </div>

默认所有目录树打开不选中, 样式为

  1. class="jstree-closed jstree-unchecked">
  1. 默认打开目录树,样式为
    1. <pre name="code" class="html">class="jstree-open jstree-unchecked"></pre><pre name="code" class="html"></pre><pre name="code" class="html">默认需要全选,样式尝试</pre><pre name="code" class="html"><pre name="code" class="html">class="jstree-open jstree-checked"></pre><pre name="code" class="html"></pre><pre name="code" class="html">3. js 加载该目录树</pre><pre name="code" class="html"><pre name="code" class="javascript"></pre><pre name="code" class="javascript">// 设置jstree 主题路径
    2. $.jstree._themes = Www_URL_JS + 'jstree/themes/';
    3. $("#cate_tree").jstree({
    4. "plugins" : [ "themes", "html_data", "checkbox", "ui" ],
    5. "themes": {
    6. "theme": "classic",
    7. "dots": true,
    8. "icons": false
    9. }
    10. });</pre><br>
    11. <br>
    12. <pre></pre>
    13. <pre name="code" class="html">默认主题 是default,是文件夹样式,classic 是 + - 号的样式<pre></pre>
    14. <pre></pre>
    15. <pre></pre>
    16. <p></p>
    17. <p><br>
    18. </p>
    19. <pre></pre>
    20. <pre name="code" class="html">4. 获取选中的值</pre><pre name="code" class="html"><pre name="code" class="javascript"></pre><pre name="code" class="javascript">var cate_ids = [];
    21. $("#cate_tree .jstree-checked").each(function(){
    22. var $this = $(this);
    23. cate_ids.push($this.attr("id"));
    24. });</pre><br>
    25. <br>
    26. <pre></pre>
    27. <pre></pre>
    28. <pre name="code" class="html"></pre><pre></pre><pre name="code" class="html"></pre><pre name="code" class="html">5. 设置给定的值为选中状态</pre><pre name="code" class="html"><pre name="code" class="javascript"></pre><pre name="code" class="javascript">var cate_js_tree = $("#cate_tree").jstree({
    29. "plugins" : [ "themes", "html_data", "checkbox", "ui" ],
    30. "themes": {
    31. "theme": "classic",
    32. "dots": true,
    33. "icons": false
    34. }
    35. });
    36. cate_js_tree.bind('loaded.jstree', function () {
    37. $("#cate_tree").find("li").each(function() {
    38. var $this = $(this);
    39. for(x in cate_ids) {
    40. if ($this.attr("id") == cate_ids[x]) {
    41. $("#cate_tree").jstree("check_node", $this);
    42. }
    43. }
    44. });
    45. });</pre><br>
    46. <br>
    47. <pre></pre>
    48. <pre name="code" class="html">6. 如果还有不太明白的,可以访问官网查询,嘿嘿……<pre></pre><pre name="code" class="html">附上这个地址,本人觉得很不错,哈哈</pre><pre name="code" class="html">http://www.jstree.com/documentation/checkbox
    49. </pre>
    50. <p></p>
    51. <pre></pre>
    52. <pre></pre>
    53. <pre></pre>
    54. <pre></pre>
    55. <pre></pre>
    56. <pre></pre>
    57. <pre></pre>
    58. </pre></pre></pre></pre></pre></pre>

jquery jstree 插件的使用的更多相关文章

  1. 利用jstree插件轻松构建树应用

    最近完成了项目中的一个树状应用,第一次接触了jstree这个插件,总的来说它的官方文档还是比较详细的,但是在使用过程中还是出现了一些问题,下面我就来谈谈这款插件的使用和心得. 首先项目需要构建一棵树, ...

  2. 顶级jQuery树插件

    顶级jQuery树插件 顶级jQuery树插件 2013-03-05 17:20 139人阅读 评论(0) 收藏 举报 jsTree JsTree是一个基于jQuery的Tree控件.支持HTML.J ...

  3. 深入学习jQuery自定义插件

    原文地址:jQuery自定义插件学习 1.定义插件的方法 对象级别的插件扩展,即为jQuery类的实例增加方法, 调用:$(选择器).函数名(参数);      $(‘#id’).myPlugin(o ...

  4. [jQuery]jQuery DataTables插件自定义Ajax分页实现

    前言 昨天在博客园的博问上帮一位园友解决了一个问题,我觉得有必要记录一下,万一有人也遇上了呢. 问题描述 园友是做前端的,产品经理要求他使用jQuery DataTables插件显示一个列表,要实现分 ...

  5. 使用jQuery.form插件,实现完美的表单异步提交

    传送门:异步编程系列目录…… 时间真快,转眼一个月快结束了,一个月没写博客了!手开始生了,怎么开始呢…… 示例下载:使用jQuery.form插件,实现完美的表单异步提交.rar 月份的尾巴,今天的主 ...

  6. 为jQuery写插件

    很多场合,我们都会调用jQuery的插件去完成某个功能,比如slider. 如下图,做一个div,通过“$( "#slider" ).slider();”的方式直接将div变成sl ...

  7. bootstrap-简洁实用的jQuery手风琴插件

    前端 <html lang="zh"> <head> <meta charset="UTF-8"> <meta htt ...

  8. 推荐15款响应式的 jQuery Lightbox 插件

    利用现代 Web 技术,网络变得越来越轻巧与.模态框是突出展现内容的重要形式,能够让用户聚焦到重要的内容上去.在这个列表中,我们编制了15款响应式的 jQuery 灯箱库,这将有助于开发人员创建和设计 ...

  9. Chocolat.js – 响应式的 jQuery Lightbox 插件

    Chocolat.js 使您能够显示一个或多个图像在同一页面上.给用户展示一组图片缩略图,可以显示全页或块.Chocolat.js 可以很好地处理所有主要的浏览器.它在下面这些浏览器测试通过:IE7+ ...

随机推荐

  1. BP神经网络及其在教学质量评价中 的应用

    本文学习笔记是自己的理解,如有错误的地方,请大家指正批评.共同进步.谢谢! 之前的教学质量评价,仅仅是通过对教学指标的简单处理.如求平均值或人为的给出各指标的权值来加权求和,其评价结果带有非常大主观性 ...

  2. vmware9.0 install ubuntu

    1)安装vmware 9.0  + 注册码2)因为是.bundle文件,执行下列命令:sudo chmod +x VMware-Workstation-7.1.1-282343.i386.bundle ...

  3. 【oracle11g,18】存储结构:暂时表,手工条带化,表/索引迁移表空间,删除表,外部表

    一. 暂时表 暂时表放在暂时表空间,不生成redo,仅仅有undo. 在暂时表中能够创建索引.视图及触发器,还能够使用"Export and Import(导出和导入)"或&quo ...

  4. Analyze提示:Value stored to &quot;***&quot;is never read

    text这个变量没有被使用,在当前类中搜索'text'这个变量发现仅仅是被赋值并没有被使用. 提示意思是:删除或者凝视这行代码;

  5. UVa 12279 - Emoogle Balance

    题目:给你n个数字推断.零和非零数字的个数差. 分析:简单题. 读入数据非零+1.为零-1. 说明:目标650题╮(╯▽╰)╭. #include <iostream> #include ...

  6. splay专题复习——bzoj 3224 &amp; 1862 &amp; 1503 题解

    [前言]快要省选二试了.上次去被虐出翔了~~这次即便是打酱油.也要打出风採!于是暂停新东西的学习.然后開始复习曾经的知识,为骗分做准备.PS:区间翻转的临时跳过,就算学了也来不及巩固了. [BZOJ3 ...

  7. Java 实现简答的单链表的功能

    作者:林子木  博客网址:http://blog.csdn.net/wolinxuebin 參考网址:http://blog.csdn.net/sunsaigang/article/details/5 ...

  8. bzoj 3312 No Change

    题目大意: 到商场购物,他的钱包里有K个硬币 想按顺序买 N个物品,第i个物品需要花费c(i)块钱 在依次进行的购买N个物品的过程中,可以随时停下来付款,每次付款只用一个硬币 支付购买的内容是从上一次 ...

  9. 洛谷 P3806 点分治模板

    题目:https://www.luogu.org/problemnew/show/P3806 就是点分治~ 每次暴力枚举询问即可,复杂度是 nmlogn: 注意 tmp[0]=1 ! 代码如下: #i ...

  10. 你真的懂SDWebImage?

    SDWebImage已经到了用烂了的地步,对于一名优秀的开发者来说,会用只是最简单的一步,我们要能够研究到其底层的技术实现和设计思路原理.在网上偶然间看到了一篇文章,感觉不错,略作修改,批注,后面的内 ...