看不懂!算了给原代码
<span><input type=checkbox>企业</span>
<UL id=root> <LI><span><input type=checkbox>企业一部</span>
<UL>
<LI><span><input type=checkbox>企业一部分部1</span>
<UL>
<LI><span><input type=checkbox>企业一部分部1aaaa</span>
<LI><span><input type=checkbox>企业一部分部1bbbb</span>
</UL>
<LI><span><input type=checkbox>企业一部分部2</span>
<UL>
<LI><span><input type=checkbox>企业一部分部2aaaa</span>
<LI><span><input type=checkbox>企业一部分部2bbbb</span>
</UL>
</UL>
<LI><span><input type=checkbox>企业二部</span>
<UL>
<LI><span><input type=checkbox>企业二部分部1</span>
<UL>
<LI><span><input type=checkbox>企业二部分部1aaaaa</span>
<LI><span><input type=checkbox>企业二部分部1bbbbb</span>
</UL>
<LI><span><input type=checkbox>企业二部分部2</span>
<UL>
<LI><span><input type=checkbox>企业二部分部2aaaaa</span>
<LI><span><input type=checkbox>企业二部分部2bbbbb</span>
</UL>
</UL>
</UL>
</div>就是将数据表中的数据如上表示!再看不懂,俺也没有办法了
<span><input type=checkbox>企业</span>
<UL id=root> <LI><span><input type=checkbox>企业一部</span>
<UL>
<LI><span><input type=checkbox>企业一部分部1</span>
<UL>
<LI><span><input type=checkbox>企业一部分部1aaaa</span>
<LI><span><input type=checkbox>企业一部分部1bbbb</span>
</UL>
<LI><span><input type=checkbox>企业一部分部2</span>
<UL>
<LI><span><input type=checkbox>企业一部分部2aaaa</span>
<LI><span><input type=checkbox>企业一部分部2bbbb</span>
</UL>
</UL>
<LI><span><input type=checkbox>企业二部</span>
<UL>
<LI><span><input type=checkbox>企业二部分部1</span>
<UL>
<LI><span><input type=checkbox>企业二部分部1aaaaa</span>
<LI><span><input type=checkbox>企业二部分部1bbbbb</span>
</UL>
<LI><span><input type=checkbox>企业二部分部2</span>
<UL>
<LI><span><input type=checkbox>企业二部分部2aaaaa</span>
<LI><span><input type=checkbox>企业二部分部2bbbbb</span>
</UL>
</UL>
</UL>
</div>就是将数据表中的数据如上表示!再看不懂,俺也没有办法了
<%
dim count
set rs=Server.CreateObject("ADODB.Recordset")
rs.open "select Name,ProductClassID,ProductClass1ID from ProductClass1 order by ProductClass1ID ",conn,1,1
%>
<script language="JavaScript">
<!--
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("Name"))%>","<%= rs("ProductClassID")%>","<%= rs("ProductClass1ID")%>");
<%
count = count + 1
rs.movenext
loop
rs.close
%>
onecount=<%=count%>;function changelocation(locationid)
{
document.form1.Nclassid.length = 0; var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.form1.Nclassid.options[document.form1.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
-->
</script><HTML>
<HEAD>
<TITLE>search</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="style.css">
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<!-- ImageReady Slices (search.psd) -->
<%Dim sqlText,sqlText1%>
<table width="400" border="0" cellpadding="5" cellspacing="1" bgcolor="#FF9900">
<form name="form1" method="POST" action="search_shangpin.asp?flag=1">
<tr bgcolor="#FFFFFF">
<td width="26%" align="center" background="images/search_09.gif">总类别</td>
<td background="images/search_09.gif"><select name="anclassid" size="1" id="anclassid" onChange="changelocation(document.form1.anclassid.options[document.form1.anclassid.selectedIndex].value)" style="border:0px solid #000000; FONT-FAMILY: 宋体; FONT-SIZE: 9pt;color:#000000; background-color:#ffffff">
<%Dim tempValue
sqlText="Select ProductClassID,Name From ProductClass"
%>
<option value="1" selected>---请选择---</option>
<% rs.open sqlText,conn,1,3
If Not (rs.eof And rs.bof) Then
tempValue=rs("ProductClassID")
%>
<option value="<%=tempValue%>"><%=rs("Name")%></option>
<%rs.movenext
While Not rs.eof
%>
<option value="<%=rs("ProductClassID")%>"><%=rs("Name")%></option>
<%
rs.movenext
Wend
End If
rs.close
%>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center" background="images/search_09.gif">商品类别</td>
<td background="images/search_09.gif"><select name="Nclassid" style="border:0px solid #000000; FONT-FAMILY: 宋体; FONT-SIZE: 9pt;color:#000000; background-color:#ffffff">
<option value="1" selected>---请选择---</option>
<%sqlText="Select ProductClass1ID,Name From ProductClass1 Where ProductClassID='" & tempValue & "'"
rs.open sqlText,conn,1,3
If Not (rs.eof And rs.eof) Then %>
<option value="<%=rs("ProductClass1ID")%>"><%=rs("Name")%></option>
<%
rs.movenext
while not rs.eof
%>
<option value="<%=rs("ProductClass1ID")%>"><%=rs("Name")%></option>
<%rs.movenext
wend
End If
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</select></td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2" background="images/search_09.gif"><input name="imageField" type="image" src="IMAGES/search_182.gif" width="54" height="18" border="0"></td>
</tr>
</form>
</table>
<!-- End ImageReady Slices -->
</BODY>
</HTML>
<!-- #Include File=../buttom.asp -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试用的搜索菜单</title>
</head>
<body>
<form name="quicksearch" method="post" action="">
<script language="JavaScript">
var po_ca_show = new Array();
var po_ca_value = new Array();
var po_detail_show = new Array();
var po_detail_value = new Array();
po_ca_show[0]='概念解释';
po_ca_value[0]='s00';
po_detail_show[0]=new Array();
po_detail_value[0]=new Array();po_detail_show[0][0]='请选择';
po_detail_value[0][0]='';
po_detail_show[0][1]='概念解释1';
po_detail_value[0][1]="herf=http://www.sohu.com";
po_detail_show[0][2]='概念解释2';
po_detail_value[0][2]='http://www.163.com';
po_detail_show[0][3]='概念解释3';
po_detail_value[0][3]='http://www.sina.com.cn';/*这里放一些我的备份吧
<select name="selectb" style="width:90" onchange="location=value">
*/
function Do_po_Change(from)
{
var num,n, i, m;
num= GetObjID('selecta');
m = document.quicksearch.elements[num].selectedIndex-1;
n = document.quicksearch.elements[num + 1].length; for(i = n - 1; i >= 0; i--)
document.quicksearch.elements[num + 1].options[i] = null; if (m>=0)
{
for(i = 0; i < po_detail_show[m].length; i++)
{
NewOptionName = new Option(po_detail_show[m][i], po_detail_value[m][i]);
document.quicksearch.elements[num + 1].options[i] = NewOptionName;
} document.quicksearch.elements[num + 1].options[0].selected = true;
}
}
function GetObjID(ObjName)
{
for (var ObjID=0; ObjID < window.quicksearch.elements.length; ObjID++)
if ( window.quicksearch.elements[ObjID].name == ObjName )
{
return(ObjID);
break;
}
return(-1);
}
</script>
<table width="250" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><select name="selecta" style="width:90" onChange="Do_po_Change(this);">
<option value="000">请选择目录</option>
<option value="s00">概念解释</option>
</select></td>
<td><select name="selectb" style="width:90" onchange="location=value">
</select></td>
</tr>
</table>
</form>
</body>
</html>
可以见http://community.csdn.net/Expert/topic/3157/3157582.xml?temp=.9448511
中awaysrain(绝对零度)(新的一年,新的开始)的回答!若谁能考虑出来 200分!因为对于几个问题我已经发出500分了!有能力就来拿!及时和有效的回答我都会加分的。
<%!
String sId;
String sName;
String sTemp;
ResultSet rset=null;
int iCount=0;
int iLen = 0;
int iLength = 3;
int iLens=3;
%>
<div>
<span><input type=checkbox>企业</span>
<UL id=root>
<%
rset=conn.executequery("select * from tree order by id");
//主目录信息
while (rset.next())
{
sId = rset.getString("id");
iLen = sId.length();
sName=rset.getString("name");
ResultSet rs = conn.executequery("select count(*) as icount from tree where id like: '"+sId+"%'");
if(rs.next()) iCount = rs.getInt("icount");//得到是否有下级目录
if(iCount==1)
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<%
}
if((iCount>1)&&((iLength-iLen==0)||(iLen % iLength==0)))
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<UL>
<%
}
if(iLen-iLens<0)
{
%>
</UL><%
} iLens = iLen;
}
%>
</UL>
</div>
运行结果:
<html>
<head>
<title>
ok
</title>
</head><body bgcolor="#ffffff">
<div>
<span><input type=checkbox>企业</span>
<UL id=root> <LI><span><input type=checkbox value=001> 生产部门</span>
<UL> <LI><span><input type=checkbox value=001001> 生产一部</span>
<UL> <LI><span><input type=checkbox value=001001001> 6767567567</span> <LI><span><input type=checkbox value=001001002> 54747546745</span> <LI><span><input type=checkbox value=001002> 生产二部门</span> </UL>
<LI><span><input type=checkbox value=002> 开发部门</span> </UL>
<LI><span><input type=checkbox value=003> 系统部门</span> <LI><span><input type=checkbox value=004> 市场部门</span></UL>
</div>
</body>
</html>
如何达到:
<html>
<head>
<title>
ok
</title>
</head><body bgcolor="#ffffff">
<div>
<span><input type=checkbox>企业</span>
<UL id=root> <LI><span><input type=checkbox value=001> 生产部门</span>
<UL> <LI><span><input type=checkbox value=001001> 生产一部</span>
<UL> <LI><span><input type=checkbox value=001001001> 6767567567</span> <LI><span><input type=checkbox value=001001002> 54747546745</span>
</UL> <LI><span><input type=checkbox value=001002> 生产二部门</span>
</UL> <LI><span><input type=checkbox value=002> 开发部门</span>
<LI><span><input type=checkbox value=003> 系统部门</span> <LI><span><input type=checkbox value=004> 市场部门</span></UL>
</div>
</body>
</html>
你把字符串连接用StringBuffer代替效率会高好多======================package cx;
import java.sql.*;
import pubpkg.ExecDb;public class AreaTreeBean {
private String treeString;
private ExecDb conn;
//构造函数
public AreaTreeBean(){
treeString="";
conn = new ExecDb();
}
public void init(){ }
public void makeTree(String areaCode,String areaName,int parentSLevel, int level) throws Exception{
String strSql = "select * from area where code like '" + areaCode + "%' and code<>'" + areaCode + "' order by s_level";
ResultSet rs;
System.out.println(strSql);
rs = conn.executeQuery(strSql);
String tempStr = "";
for(int i=1;i<level;i++)
{
tempStr +="  ";
}
if (!rs.next())
{
treeString += "<table border=0 cellpadding=0 cellspacing=0 width=100% >" +"\n";
treeString += " <tr>" +"\n";
treeString += " <td nowrap>" + tempStr + "<img src=../Images/end.gif><input type=checkbox name=mycheckbox id=checkbox" + areaCode + " value=" + areaName + " onClick=\"getArea('checkbox" + areaCode+"','"+areaName+"')\">" + areaName + "</td>" +"\n";
treeString += " </tr>" +"\n";
treeString += "</table>" +"\n";
}
else
{
treeString += "<table border=0 cellpadding=0 cellspacing=0 width=100%>" +"\n";
treeString += " <tr>" +"\n";
treeString += " <td nowrap>" + tempStr + "<img src=../Images/Closed.gif id=Out" + areaCode + " style=cursor:Hand class=cItem><input type=checkbox name=mycheckbox id=checkbox" + areaCode + " value=" + areaName + " onClick=\"getArea('checkbox" + areaCode+"','"+areaName+"')\">" + areaName + "</td>" +"\n";
treeString += " </tr>" +"\n";
treeString += "</table>" +"\n";
treeString += "<div id=Out" + areaCode + "a style=display:None>" +"\n"; rs.beforeFirst();
while(rs.next())
{
String code = rs.getString("code");
String name = rs.getString("name");
int s_level = rs.getInt("s_level");
if(parentSLevel+1 == s_level) //是当前单位的下级
{
makeTree(code,name,s_level,level+1);
}
else //判断是否是直接下级
{
if(isChild(areaCode,parentSLevel,code,s_level))
{
makeTree(code,name,s_level,level+1);
}
}
} treeString += "</div>" + "\n";
}
}
//返回树的HTM字符传
public boolean isChild(String parentCode,int parentSLevel,String code,int s_level) throws Exception //判断是否直接下级
{
String tmpStr = "";
String tmpCode = code;
for(int i=s_level;i>parentSLevel+1;i--)
{
if(i>=4) //如果是乡、村级则截3位,否则截两位
{
tmpCode=tmpCode.substring(0,tmpCode.length()-3);
}
else
{
tmpCode=tmpCode.substring(0,tmpCode.length()-2);
}
tmpStr += " or code='" + tmpCode + "'";
}
if(tmpStr.length()>0)
{
tmpStr =tmpStr.substring(3,tmpStr.length());
}
String strSql = "select * from area where " + tmpStr;
ResultSet rs;
rs = conn.executeQuery(strSql);
boolean result = !rs.next();
return result;//!rs.next();
}
public String getTreeString() {
return treeString;
}
}
<%
}
if(iLen-iLens<0)
{
%>
</UL>●生产部门
□生产一部
▲6767567567
▲54747546745
▲生产二部门《《《《
□开发部门
●系统部门
●市场部门读取生产二部门的完毕时候 才满足打印</UL>
而应该在此之前打印</UL>
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<UL>
<%
}
if(iLen-iLens<0)
{
%>
</UL>所以我觉得应该将判断打印UL 和判断/UL的部分 倒过来
{
%>
</UL>
<%
}if((iCount>1)&&((iLength-iLen==0)||(iLen % iLength==0)))
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<UL>
<%
}
%>
楼主 有没有试试这个该后测试呢?
至于你信息说到:顺便说明一下,对于
if(iCount==1)
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%> </span>
<%
}
和
if((iCount>1)&&((iLength-iLen==0) ¦ ¦(iLen % iLength==0)))
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%> </span>
<UL>
<%
}
不用怀疑正确性,关键是如何</UL>的问题/////
不是怀疑正确性问题 而是一个判断先后的问题。
这个也是处理/ul 谢谢你的题目 使我从中学到不少的知识 再见
当都有子目录的时候完全正确,当其中有一个没有子目录的时候将出现一个小问题!就是
当有一级没有子目录就自动的加到上一级的最后子目录项中
比如
<div>
<span><input type=checkbox>企业</span>
<UL id=root> <LI><span><input type=checkbox value=001> 生产部门 </span>
<UL> <LI><span><input type=checkbox value=001001> 生产一部 </span> <LI><span><input type=checkbox value=001002> 生产二部 </span> </UL> <LI><span><input type=checkbox value=002> 业务部门 </span>
<UL> <LI><span><input type=checkbox value=002001> 业务部门1 </span> <LI><span><input type=checkbox value=002002> 业务部门2 </span> <LI><span><input type=checkbox value=002003> 业务部门3 </span> </UL> <LI><span><input type=checkbox value=004> 开发部门 </span>
<UL> <LI><span><input type=checkbox value=004001> 开发部门1 </span> <LI><span><input type=checkbox value=004002> 开发部门2 </span> <LI><span><input type=checkbox value=005> 策划部门 </span> </UL> <LI><span><input type=checkbox value=006> 企业规划部 </span>
<UL> <LI><span><input type=checkbox value=006001> 企业规划部 1 </span> <LI><span><input type=checkbox value=006002> 企业规划部 2 </span> <LI><span><input type=checkbox value=006003> 企业规划部 3 </span> <LI><span><input type=checkbox value=006004> 企业规划部 4 </span></UL>
</div>
看出来有什么不对吗?
应该的运行结果是
<div>
<span><input type=checkbox>企业</span>
<UL id=root> <LI><span><input type=checkbox value=001> 生产部门 </span>
<UL> <LI><span><input type=checkbox value=001001> 生产一部 </span> <LI><span><input type=checkbox value=001002> 生产二部 </span> </UL> <LI><span><input type=checkbox value=002> 业务部门 </span>
<UL> <LI><span><input type=checkbox value=002001> 业务部门1 </span> <LI><span><input type=checkbox value=002002> 业务部门2 </span> <LI><span><input type=checkbox value=002003> 业务部门3 </span> </UL> <LI><span><input type=checkbox value=004> 开发部门 </span>
<UL> <LI><span><input type=checkbox value=004001> 开发部门1 </span> <LI><span><input type=checkbox value=004002> 开发部门2 </span>
</UL> <LI><span><input type=checkbox value=005> 策划部门 </span> <LI><span><input type=checkbox value=006> 企业规划部 </span>
<UL> <LI><span><input type=checkbox value=006001> 企业规划部 1 </span> <LI><span><input type=checkbox value=006002> 企业规划部 2 </span> <LI><span><input type=checkbox value=006003> 企业规划部 3 </span> <LI><span><input type=checkbox value=006004> 企业规划部 4 </span></UL>
</div>当策划部门中有内容的时候就是正确的
解答在
http://community.csdn.net/Expert/TopicView3.asp?id=3157582