JSP页面文件目录树源码(递归算法)

2008-02-23 07:51:01来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312"; >
<script language="JavaScript">
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i =2) eval(args[i] ".location='" args[i 1] "'");
}
//-->
</script>
<link href="css/ip.css" rel="stylesheet" type="text/css">
</head>

<body topmargin = "0" leftmargin = "0" marginheight = "0" marginwidth = "0" bgcolor="#FFFFFF">
<table border="0" cellspacing="0" cellpadding="0" height="80%">
<tr><td>
</td>
</tr>
<tr valign="top">
<td height="223"> <span id="menus"></span>
<span id="view"></span>

</td>
</tr>
<tr valign="bottom">
<td>&nbsp;</td>
</tr>
</table>
<div align="right"></div>
</body>
<script>
/**
* 构造树,初值为0
*/
function isbrother()
{
var is=flase;

}
function tree(n) {
var id = new Array("bar","pad","<IMG src='images/midnodeline.gif'border=0 align='absmiddle'><IMG src='images/close.gif 'border=0 align='absmiddle'>","<IMG src='images/midclosedfolder.gif 'border=0 align='absmiddle'><IMG src='images/close.gif 'border=0 align='absmiddle'>","<IMG src='images/lastnodeline.gif'border=0 align='absmiddle'><IMG src='images/close.gif 'border=0 align='absmiddle'>");
if(n == 0) { // 初始化变量
n = 1;
i = 0;
s = "";
}
s = "<table border=0 cellspacing=0 cellpadding=0 >";
for(;i<tree_ar.length-1;i ) {
var k = (n >= tree_ar[i 1][0])?0:1;
if(tree_ar[i][2]==false)
{
id[2]="<IMG src='images/lastnodeline.gif'border=0 align='absmiddle'><IMG src='images/close.gif 'border=0 align='absmiddle'>";
}
s = "<tr id='" id[k] "' value=" i "><td >" id[k 2] "</td><td>" tree_ar[i][1] "</td></tr>"; // // 构造节点,注意这里的自定义属性value。作用是简化构造节点的描述,共享参数数组信息。
if(n > tree_ar[i 1][0]) { // 若期望层次大于当前层次,结束本层次返回上一层次。
s = "</td></tr></table>";
return tree_ar[i 1][0];
}
if(n < tree_ar[i 1][0]) { // 若期望层次小于当前层次,递归进入下一层次。
s = "<tr style='display:none' ><td ";
if(tree_ar[i][2]==true)
{ //如果有下个兄弟节点,则画兄弟节点间的连线
s ="background='images/line.gif' border=0 align='absmiddle'";
}

s ="></td><td>";
var m = tree(tree_ar[ i][0]);
s = "</td></tr>";
if(m < n) { // 当递归返回值小于当前层次期望值时,将产生连续的返回动作
s = "</table>";
return m;
}
}
}
s = "</table>";
return s;
}
</script>

<script for=pad event=onclick>
// 分枝节点的点击响应
v = this.parentElement.rows[this.rowIndex 1].style;
if(v.display == 'block') {
v.display = 'none';
this.cells[0].innerHTML = "<IMG src='images/midclosedfolder.gif 'border=0 align='absmiddle'><IMG src='images/close.gif 'border=0 align='absmiddle'>";
view.innerHTML = "";// 自行修改为参数数组定义的闭合动作
}else {
v.display = 'block';
this.cells[0].innerHTML = "<IMG src='images/midopenedfolder.gif 'border=0 align='absmiddle'><IMG src='images/open.gif 'border=0 align='absmiddle'>";
// view.innerHTML = "<b>" tree_ar[this.value][1] "</b>"; // 自行修改为参数数组定义的展开动作
}

/**
* 以下代码用于关闭已展开的其他分枝
* 如需自行关闭展开的分枝则从这里直接返回或删去这段代码
*/
if(! tree_ar[this.value].type) //如该节点为首次进入,则记录所在层次信息
genTreeInfo(this);
var n = 1*this.value 1;
for(i=n;i<tree_ar.length-1;i ) { // 关闭排列在当前节点之后的树
if(tree_ar[i].type == "pad") {
tree_ar[i].obj2.style.display = 'none';
tree_ar[i].obj1.cells[0].innerHTML = "<IMG src='images/midclosedfolder.gif 'border=0 align='absmiddle'><IMG src='images/close.gif 'border=0 align='absmiddle'>";
}
}
while(tree_ar[--n][0] > 1); //回溯到当前树的起点
while(--n >= 0) // 关闭排列在当前树的起点之前的树
if(tree_ar[n].type == "pad") {
tree_ar[n].obj2.style.display = 'none';
tree_ar[n].obj1.cells[0].innerHTML = "<IMG src='images/midclosedfolder.gif 'border=0 align='absmiddle'><IMG src='images/open.gif 'border=0 align='absmiddle'>";
}


/** 记录层次信息,用以简化遍历树时的复杂的节点描述 **/
function genTreeInfo(o) {
var el = o.parentElement;
for(var i=0;i<el.rows.length;i ) {
if(el.rows[i].id != "") {
tree_ar[el.rows[i].value].type = el.rows[i].id;
}
if(el.rows[i].id == "pad") {
tree_ar[el.rows[i].value].obj1 = el.rows[i];
tree_ar[el.rows[i].value].obj2 = el.rows[i 1];

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JSP语法

下一篇:JSP连接sybase数据库中文显示问题终极解决办法