使用jquery的treeview插件建立树状图

来源:互联网 发布:哪个返利网好 知乎 编辑:程序博客网 时间:2024/04/28 08:46

http://docs.jquery.com/Plugins/Treeview到这里下载压缩包

下面是个例子

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><link rel="stylesheet" href="../catalog/jquery.treeview.css" /><script src="jquery.js" type="text/javascript"></script><script src="jquery.cookie.js" type="text/javascript"></script><script src="jquery.treeview.js" type="text/javascript"></script></head><body><script type="text/javascript">$(document).ready(function() {$("#example").treeview({//需要最外层ul的idcollapsed: true,//默认折叠animated: "medium",//动画效果速度control:"#sidetreecontrol",persist: "location"});});</script><div id="treeviewDiv"><ul id="example" class="filetree"><li><span class="folder">Folder 1</span><ul><li><a href="http://www.sina.com.cn" class="file" target="baseframe">Item 1.1</a></li></ul></li><li><span class="folder">Folder 2</span><ul><li><span class="folder">Subfolder 2.1</span><ul><li><span class="file">File 2.1.1</span></li><li><span class="file">File 2.1.2</span></li></ul></li><li><span class="file">File 2.2</span></li></ul></li><li class="closed"><span class="folder">Folder 3 (closedat start)</span><ul><li><span class="file">File 3.1</span></li></ul></li><li><span class="file">File 4</span></li></ul></div></body></html>

我理解的一个一个root级的结点代码应该是

<ul>此root结点的外层ul     <li>一个li表示一行内容        <span></span>或<a></a>span或a标签可以设置显示标题和图片,a标签的话自定义点击事件比较轻松        <ul> ul标签用于想内部插入非root子节点或root子结点        </ul>     </li></ul>


而非root级的就是一个li就行了

<li>   <a><span></span></a></li>


只要html代码复合ul li规范执行一行命令即可

$("#example").treeview({//需要最外层ul的idcollapsed: true,//默认折叠animated: "medium",//动画效果速度control:"#sidetreecontrol",persist: "location"});