请教jstree的一些用法

强迫症专用头像 2013-02-28 10:58:34
现在有一个jstree生成的树,我想通过函数调用模拟节点点击,请问如何实现?
...全文
212 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
自己解答了: $.jstree._focused().deselect_node("#child_2_2"); $.jstree._focused().select_node("#child_2_4"); 第一个是取消选中的节点id,第二个是选中的节点id
Go 旅城通票 2013-02-28
  • 打赏
  • 举报
回复
就是通过自己写的带代码展开指定的节点,而不是靠鼠标点击? 楼主可以研究下ui plugin和crrm plugin这2个插件的API http://www.jstree.com/documentation/ui http://www.jstree.com/documentation/crrm JSTree API:http://www.jstree.com/documentation
bbjbepzz 2013-02-28
  • 打赏
  • 举报
回复
直接触发它的click事件就可以了 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jsTree v.1.0 - Demo</title> <script type="text/javascript" src="../_lib/jquery.js"></script> <script type="text/javascript" src="../_lib/jquery.cookie.js"></script> <script type="text/javascript" src="../_lib/jquery.hotkeys.js"></script> <script type="text/javascript" src="../jquery.jstree.js"></script> <link type="text/css" rel="stylesheet" href="../_docs/syntax/!style.css" /> <link type="text/css" rel="stylesheet" href="../_docs/!style.css" /> <script type="text/javascript" src="../_docs/syntax/!script.js"></script> </head> <body id="demo_body"> <div id="container"> <h1 id="dhead">jsTree v.1.0</h1> <h1>DEMO</h1> <h2>Creating a tree, binding events, using the instance</h2> <div id="description"> <p>Here is how you create an instance, bind an event and then get the instance.</p> <div id="demo1" class="demo" style="height: 100px;"> <ul> <li id="phtml_1"><a href="#">Root node 1</a> <ul> <li id="phtml_2"><a href="#">Child node 1</a></li> <li id="phtml_3"><a href="#">Child node 2</a></li> </ul></li> <li id="phtml_4"><a href="#">Root node 2</a></li> </ul> </div> <button id="btn">点击Child node 2</button> <script type="text/javascript" class="source below"> $(function() { $('#btn').click(function() { $('#phtml_3 a').click(); }); $("#demo1") .jstree( { "plugins" : [ "themes", "html_data", "ui", "crrm", "hotkeys" ], "core" : { "initially_open" : [ "phtml_1" ] } }) .bind("loaded.jstree", function(event, data) { }).delegate("a", "click", function(event, data) { alert('被点击了') }); }); </script> </div> </body> </html>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧