熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JSP+JavaScript實現類似MSDN CSDN導航樹效果代碼

2022-06-13   來源: JSP教程 

  <! Treejsp >
<%@ page contentType ="text/html;charset=gb" %>
<%@ page import="javautil*;" %>
<!DOCTYPE HTML PUBLIC "//WC//DTD HTML Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<iframe width="%" height="" id="hiddenframe"></iframe>
<script>
function ExpandNode(ParentNodeParentId){
var NodeX = eval(ParentNodeid + _);
if (NodeXstyledisplay == none)
 {
  NodeXstyledisplay="block";
  if (NodeXloaded == no)
     {
      documentframes[hiddenframe]locationreplace("subtreejsp?PID=" + ParentId + "&PNode=" + ParentNodeid);
      NodeXloaded = yes;
    }
 }
else
 {
  NodeXstyledisplay=none;
 }
}
</script>
<CENTER>
<TABLE border="" width="%" height="%">
<TR>
<TD>
<DIV style="OVERFLOW: auto;WIDTH: %;HEIGHT: %">
<TABLE width="%">
<TR>
<TD>
<%
 javalangClassforName("sunjdbcodbcJdbcOdbcDriver");
//  javasqlConnection ConnectionX = javasqlDriverManagergetConnection("jdbc:ODBC:driver={Microsoft Access Driver (*mdb)};DBQ=D:\\Resin\\doc\\examples\\Tree\\treemdb""admin" "");
//  javasqlStatement StatementX = ConnectionXcreateStatement();
 javasqlResultSet ResultSetX = javasqlDriverManagergetConnection("jdbc:ODBC:driver={Microsoft Access Driver (*mdb)};DBQ=e:\\resin\\doc\\examples\\Tree\\treemdb""admin" "")createStatement()executeQuery("select *(select count(*) from tree where parentid = Tid) as children from tree T where parentid = ");
 int i=;
 int children;
 int ID;
 while (ResultSetXnext())
       {
children=ResultSetXgetInt("children");
ID=ResultSetXgetInt("id");
%>
<div id=Node_<%= i %>><a #
        <% if (children >)
              {%>
                 onClick=ExpandNode(Node_<%= i %><%=ID %>)>+</a>
              <%;}
            else {%>
                ></a><%;}%>
        <a #
        <% if (children >)
                {%>
                    onDblClick=ExpandNode(Node_<%= i %><%=ID%>)
                <%}  %>  
                >
                <%=ResultSetXgetString("remark")%></a>
</div>
        
<div id=Node_<%= i %>_ style=display: none loaded=no>
        &nbsp;&nbsp;正在加載
   </div>
 <%
 i++;
 }
 %>
</BODY>
</HTML>

  <! SubTreejsp >
<%@ page contentType ="text/html;charset=gb" %>
<%@ page import="javautil*;" %>
<!DOCTYPE HTML PUBLIC "//WC//DTD HTML Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<%
String ParentNode = requestgetParameter("PNode");
int i;
int j;
String nSpace="";
j= ParentNodelength() ParentNodereplaceAll("_""")length();
for (i=;i<j;i++)
   nSpace = nSpace + "&nbsp;&nbsp;";
String sHTML ="";
i=;

  javalangClassforName("sunjdbcodbcJdbcOdbcDriver");
//  javasqlConnection ConnectionX = javasqlDriverManagergetConnection("jdbc:ODBC:driver={Microsoft Access Driver (*mdb)};DBQ=D:\\Resin\\doc\\examples\\Tree\\treemdb""admin" "");
//  javasqlStatement StatementX = ConnectionXcreateStatement();
 javasqlResultSet ResultSetX = javasqlDriverManagergetConnection("jdbc:ODBC:driver={Microsoft Access Driver (*mdb)};DBQ=e:\\resin\\doc\\examples\\Tree\\treemdb""admin" "")createStatement()executeQuery("select *(select count(*) from tree where parentid =Tid ) as Children from tree T where parentid = " + requestgetParameter("PID"));
 int children;
 int ID;
 while (ResultSetXnext())
 {    children=ResultSetXgetInt("children");
      ID=ResultSetXgetInt("id");
      sHTML = sHTML + "<div id=" + ParentNode + "_" + (i + ) + ">" + nSpace + "<a #";
  if (children >)
     sHTML = sHTML + " onClick=ExpandNode(" + ParentNode + "_" + (i + ) + "" + ID + ")>+";
  else sHTML = sHTML + ">";
      sHTML = sHTML + "</a>\\n" + "<a #";
  if (children >)
     sHTML = sHTML + " onDblClick=ExpandNode(" + ParentNode + "_" + (i + ) + "" + ID + ")";
  sHTML = sHTML + ">" + ID + ": " + ResultSetXgetString("remark") + "</a></div>";
  if (children >)
     sHTML = sHTML + "<div id=" + ParentNode + "_" + (i + ) + "_ style=display: none loaded=no>" + nSpace + "&nbsp;&nbsp;正在加載 </div>";
 %>
 <% i++;
    }%>
<BODY>
<script>
   var x = eval(parent + <%= ParentNode + "_"%> ) ;
   xinnerHTML="<%= sHTML %>";
</script>
</BODY>
</HTML>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20522.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.