JSP + JavaScript 实现类似 MSDN CSDN 导航树效果!
时间:2007-02-17 来源:PHP爱好者
测试站点:
http://www.triaton.com.cn:1080/examples/tree/tree.jsp 类似 MSDN CSDN 导航树效果,JSP + Javas cript 实现! <!-- Tree.jsp -->
<%@ page contentType ="text/html;charset=gb2312" %>
<%@ page import="java.util.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Des cription" CONTENT="">
</HEAD>
<BODY>
<iframe width="100%" height="100" id="hiddenframe"></iframe>
<s cript>
function ExpandNode(ParentNode,ParentId){
var NodeX = eval(ParentNode.id + '_0');
if (NodeX.style.display == 'none')
{
NodeX.style.display="block";
if (NodeX.loaded == 'no')
{
document.frames['hiddenframe'].location.replace("subtree.jsp?PID=" + ParentId + "&PNode=" + ParentNode.id);
NodeX.loaded = 'yes';
}
}
else
{
NodeX.style.display='none';
}
}
</s cript>
<CENTER>
<TABLE border="1" width="20%" height="60%">
<TR>
<TD>
<DIV style="OVERFLOW: auto;WIDTH: 100%;HEIGHT: 100%">
<TABLE width="300%">
<TR>
<TD>
<%
java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// java.sql.Connection ConnectionX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=D:ResindocexamplesTreetree.mdb","admin", "");
// java.sql.Statement StatementX = ConnectionX.createStatement();
java.sql.ResultSet ResultSetX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=e:resin-2.1.6docexamplesTreetree.mdb","admin", "").createStatement().executeQuery("select *,(select count(*) from tree where parentid = T.id) as children from tree T where parentid = 0");
int i=0;
int children;
int ID;
while (ResultSetX.next())
{
children=ResultSetX.getInt("children");
ID=ResultSetX.getInt("id");
%>
<div id='Node_<%= i %>'><a href='#'
<% if (children >0)
{%>
onClick='ExpandNode(Node_<%= i %>,<%=ID %>)'>+</a>
<%;}
else {%>
>-</a><%;}%>
<a href='#'
<% if (children >0)
{%>
onDblClick='ExpandNode(Node_<%= i %>,<%=ID%>)'
<%} %>
>
<%=ResultSetX.getString("remark")%></a>
</div>
<div id='Node_<%= i %>_0' style='display: none' loaded='no'>
正在加载 ...
</div>
<%
i++;
}
%>
</BODY>
</HTML> <!-- SubTree.jsp -->
<%@ page contentType ="text/html;charset=gb2312" %>
<%@ page import="java.util.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Des cription" CONTENT="">
</HEAD>
<%
String ParentNode = request.getParameter("PNode");
int i;
int j;
String nSpace="";
j= ParentNode.length()- ParentNode.replaceAll("_","").length();
for (i=0;i<j;i++)
nSpace = nSpace + " ";
String sHTML ="";
i=0; java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// java.sql.Connection ConnectionX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=D:ResindocexamplesTreetree.mdb","admin", "");
// java.sql.Statement StatementX = ConnectionX.createStatement();
java.sql.ResultSet ResultSetX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=e:resin-2.1.6docexamplesTreetree.mdb","admin", "").createStatement().executeQuery("select *,(select count(*) from tree where parentid =T.id ) as Children from tree T where parentid = " + request.getParameter("PID"));
int children;
int ID;
while (ResultSetX.next())
{ children=ResultSetX.getInt("children");
ID=ResultSetX.getInt("id");
sHTML = sHTML + "<div id='" + ParentNode + "_" + (i + 1) + "'>" + nSpace + "<a href='#'";
if (children >0)
sHTML = sHTML + " onClick='ExpandNode(" + ParentNode + "_" + (i + 1) + "," + ID + ")'>+";
else sHTML = sHTML + ">-";
sHTML = sHTML + "</a>n" + "<a href='#'";
if (children >0)
sHTML = sHTML + " onDblClick='ExpandNode(" + ParentNode + "_" + (i + 1) + "," + ID + ")'";
sHTML = sHTML + ">" + ID + ": " + ResultSetX.getString("remark") + "</a></div>";
if (children >0)
sHTML = sHTML + "<div id='" + ParentNode + "_" + (i + 1) + "_0' style='display: none' loaded='no'>" + nSpace + " 正在加载 ...</div>";
%>
<% i++;
}%>
<BODY>
<s cript>
var x = eval('parent.' + '<%= ParentNode + "_0"%>' ) ;
x.innerHTML="<%= sHTML %>";
</s cript>
</BODY>
</HTML>
php爱好者 站 http://www.phpfans.net 网页制作|网站建设|数据采集.
http://www.triaton.com.cn:1080/examples/tree/tree.jsp 类似 MSDN CSDN 导航树效果,JSP + Javas cript 实现! <!-- Tree.jsp -->
<%@ page contentType ="text/html;charset=gb2312" %>
<%@ page import="java.util.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Des cription" CONTENT="">
</HEAD>
<BODY>
<iframe width="100%" height="100" id="hiddenframe"></iframe>
<s cript>
function ExpandNode(ParentNode,ParentId){
var NodeX = eval(ParentNode.id + '_0');
if (NodeX.style.display == 'none')
{
NodeX.style.display="block";
if (NodeX.loaded == 'no')
{
document.frames['hiddenframe'].location.replace("subtree.jsp?PID=" + ParentId + "&PNode=" + ParentNode.id);
NodeX.loaded = 'yes';
}
}
else
{
NodeX.style.display='none';
}
}
</s cript>
<CENTER>
<TABLE border="1" width="20%" height="60%">
<TR>
<TD>
<DIV style="OVERFLOW: auto;WIDTH: 100%;HEIGHT: 100%">
<TABLE width="300%">
<TR>
<TD>
<%
java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// java.sql.Connection ConnectionX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=D:ResindocexamplesTreetree.mdb","admin", "");
// java.sql.Statement StatementX = ConnectionX.createStatement();
java.sql.ResultSet ResultSetX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=e:resin-2.1.6docexamplesTreetree.mdb","admin", "").createStatement().executeQuery("select *,(select count(*) from tree where parentid = T.id) as children from tree T where parentid = 0");
int i=0;
int children;
int ID;
while (ResultSetX.next())
{
children=ResultSetX.getInt("children");
ID=ResultSetX.getInt("id");
%>
<div id='Node_<%= i %>'><a href='#'
<% if (children >0)
{%>
onClick='ExpandNode(Node_<%= i %>,<%=ID %>)'>+</a>
<%;}
else {%>
>-</a><%;}%>
<a href='#'
<% if (children >0)
{%>
onDblClick='ExpandNode(Node_<%= i %>,<%=ID%>)'
<%} %>
>
<%=ResultSetX.getString("remark")%></a>
</div>
<div id='Node_<%= i %>_0' style='display: none' loaded='no'>
正在加载 ...
</div>
<%
i++;
}
%>
</BODY>
</HTML> <!-- SubTree.jsp -->
<%@ page contentType ="text/html;charset=gb2312" %>
<%@ page import="java.util.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Des cription" CONTENT="">
</HEAD>
<%
String ParentNode = request.getParameter("PNode");
int i;
int j;
String nSpace="";
j= ParentNode.length()- ParentNode.replaceAll("_","").length();
for (i=0;i<j;i++)
nSpace = nSpace + " ";
String sHTML ="";
i=0; java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// java.sql.Connection ConnectionX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=D:ResindocexamplesTreetree.mdb","admin", "");
// java.sql.Statement StatementX = ConnectionX.createStatement();
java.sql.ResultSet ResultSetX = java.sql.DriverManager.getConnection("jdbc:ODBC:driver={Microsoft Access Driver (*.mdb)};DBQ=e:resin-2.1.6docexamplesTreetree.mdb","admin", "").createStatement().executeQuery("select *,(select count(*) from tree where parentid =T.id ) as Children from tree T where parentid = " + request.getParameter("PID"));
int children;
int ID;
while (ResultSetX.next())
{ children=ResultSetX.getInt("children");
ID=ResultSetX.getInt("id");
sHTML = sHTML + "<div id='" + ParentNode + "_" + (i + 1) + "'>" + nSpace + "<a href='#'";
if (children >0)
sHTML = sHTML + " onClick='ExpandNode(" + ParentNode + "_" + (i + 1) + "," + ID + ")'>+";
else sHTML = sHTML + ">-";
sHTML = sHTML + "</a>n" + "<a href='#'";
if (children >0)
sHTML = sHTML + " onDblClick='ExpandNode(" + ParentNode + "_" + (i + 1) + "," + ID + ")'";
sHTML = sHTML + ">" + ID + ": " + ResultSetX.getString("remark") + "</a></div>";
if (children >0)
sHTML = sHTML + "<div id='" + ParentNode + "_" + (i + 1) + "_0' style='display: none' loaded='no'>" + nSpace + " 正在加载 ...</div>";
%>
<% i++;
}%>
<BODY>
<s cript>
var x = eval('parent.' + '<%= ParentNode + "_0"%>' ) ;
x.innerHTML="<%= sHTML %>";
</s cript>
</BODY>
</HTML>
php爱好者 站 http://www.phpfans.net 网页制作|网站建设|数据采集.
相关阅读 更多 +