dTree节点查找展开收缩示例
dTree示例,带查找节点,展开收缩查找到得节点功能,dTree下载:dTree.js下载+API文档
示例实现节点查找,并展开输入的关键字的节点
展开dTree包含关键字的节点
搜索dTree包含关键字节点
源代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>dTree示例,带查找展开收缩节点功能</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <base href="http://www.w3dev.cn/demo/dtree/"/> <link rel="StyleSheet" href="dtree.css" type="text/css" /> <script type="text/javascript" src="dtree.js"></script> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script> </head> <body> <h2>dTree示例,带查找展开收缩节点功能</h2> <input type="text" id="txtKW" /><input type="button" onclick="NodeExp(true)" value="展开节点"/><input type="button" onclick="NodeExp()" value="收缩节点" /><input type="button" onclick="doSearch()" value="搜索节点" /> <p><a href="javascript: d.openAll();">展开所有节点</a> | <a href="javascript: d.closeAll();">收缩所有节点</a></p> <div class="dtree" id="dTree"> <script type="text/javascript"> function NodeExp(exp) { var kw = $('#txtKW').val(); if (kw != '') { $("#dTree a:contains('" + kw + "')").each(function () { d[exp?'openTo':'closeTo'](this.id.replace('sd',''),true); }); } } function doSearch() { var kw = $('#txtKW').val().toLowerCase(); if (kw == '') $('#dTree').find('div.dTreeNode').show(); else $('#dTree').find('div.dTreeNode').hide().each(function () { this.style.display = $(this).text().toLowerCase().indexOf(kw) != -1 ? 'block' : 'none' }); } d = new dTree('d'); d.add(0,-1,'My example tree'); d.add(1,0,'Node 1','example01.html'); d.add(2,0,'Node 2','example01.html'); d.add(3,1,'Node 1.1','example01.html'); d.add(4,0,'Node 3','example01.html'); d.add(5,3,'Node 1.1.1','example01.html'); d.add(6,5,'Node 1.1.1.1','example01.html'); d.add(7,0,'Node 4','example01.html'); d.add(8,1,'Node 1.2','example01.html'); d.add(9,0,'My Pictures','example01.html','Pictures I\'ve taken over the years','','img/imgfolder.gif','img/imgfolder.gif'); d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir'); d.add(11,9,'Mom\'s birthday','example01.html'); d.add(12, 0, 'Recycle Bin', 'example01.html', '', '', 'img/trash.gif'); document.write(d); </script> </div> </body> </html>
加支付宝好友偷能量挖...
原创文章,转载请注明出处:dTree节点查找展开收缩示例