无限级生成下拉列表
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<br>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#FFFFFF"><div align="center">意向物品类别:</div></td>
<td bgcolor="#FFFFFF" id="catelist"><select name="yxwplb" id="yxwplb0" size="1" onchange="javascript:createcate(this.value)">
<option value="0">请选择意向类别</option>
</select>
</td>
</tr>
</table>
<script language="javascript">
maxdepth = "3";//类别最深度
var ctree = new Array();
//第一个值是类别名称,第二个值是类别ID,第三个值是类别深度,第四个值是个逻辑值,看是否有下级
var heihei_id = new Array();
ctree[0] = ["邮币/古董/字画/收藏","1000","1","1"];
ctree[1] = ["收藏类报刊/目录/图书","10001000","2","1"];
ctree[2] = ["书报刊","100010001000","3","0"];
ctree[3] = ["连环画","100010001001","3","0"];
ctree[4] = ["报纸","100010001002","3","0"];
ctree[5] = ["古玩","10001001","2","1"];
ctree[6] = ["旧紫砂/瓷器","100010011000","3","0"];
ctree[7] = ["旧家具/古木艺","100010011001","3","0"];
ctree[8] = ["文房四宝","100010011002","3","0"];
ctree[9] = ["旧旧铜器/金属器","100010011003","3","0"];
ctree[10] = ["旧玉器/旧石器","100010011004","3","0"];
ctree[11] = ["旧钟表/旧机器","100010011005","3","0"];
ctree[12] = ["织绣/烟具/古董","100010011006","3","0"];
ctree[13] = ["玉器/玉石","10001002","2","0"];
ctree[14] = ["现代紫砂/陶瓷","10001003","2","0"];
ctree[15] = ["金石篆刻","10001004","2","0"];
ctree[16] = ["奇石/观赏石/矿物晶体","10001005","2","0"];
ctree[17] = ["雕塑雕刻","10001006","2","0"];
ctree[18] = ["古董木艺","10001007","2","0"];
ctree[19] = ["古董钟表","10001009","2","0"];
ctree[20] = ["趣味收集","10001010","2","0"];
ctree[21] = ["老烟袋/烟嘴/烟具","10001011","2","0"];
ctree[22] = ["宗教收藏品","10001012","2","0"];
ctree[23] = ["老相机/老相片","10001013","2","0"];
ctree[24] = ["标牌章","10001014","2","0"];
ctree[25] = ["钱币","10001015","2","0"];
ctree[26] = ["邮品","10001016","2","0"];
ctree[27] = ["字画书法碑帖","10001017","2","0"];
ctree[28] = ["文革时期收藏品","10001018","2","0"];
ctree[29] = ["票证","10001019","2","0"];
ctree[30] = ["磁卡/卡片","10001020","2","0"];
ctree[31] = ["文房四宝","10001021","2","0"];
ctree[32] = ["老唱机/收音机/老唱片/老电器","10001022","2","0"];
ctree[33] = ["其它收藏品","10001023","2","0"];
ctree[34] = ["汽车/摩托/自行车","1001","1","1"];
ctree[35] = ["整车","10011000","2","0"];
ctree[36] = ["汽车电子电器","10011001","2","0"];
ctree[37] = ["品牌/卡通汽车饰品","10011002","2","0"];
ctree[38] = ["汽车装潢装饰品","10011003","2","0"];
ctree[39] = ["汽摩视听设备","10011004","2","0"];
ctree[40] = ["车载通讯/定位用品/GPS","10011005","2","0"];
ctree[41] = ["汽车防护保养用品","10011006","2","0"];
ctree[42] = ["汽车改装专区","10011007","2","0"];
ctree[43] = ["汽车配件","10011008","2","0"];
ctree[44] = ["摩托车及配件","10011009","2","0"];
ctree[45] = ["电动车及配件","10011010","2","0"];
ctree[46] = ["自行车及配件","10011011","2","0"];
ctree[47] = ["滑板车及配件","10011012","2","0"];
ctree[48] = ["其它汽车相关产品","10011013","2","0"];
ctree[49] = ["房产/建材装潢/五金工具","1002","1","1"];
ctree[50] = ["住宅/商铺/办公楼","10021000","2","0"];
ctree[51] = ["家具","10021001","2","0"];
ctree[52] = ["卫浴洁具","10021002","2","0"];
ctree[53] = ["灯饰灯具","10021003","2","0"];
ctree[54] = ["门窗类","10021004","2","0"];
ctree[55] = ["五金与工具","10021005","2","0"];
ctree[56] = ["家装/装潢材料","10021006","2","0"];
ctree[57] = ["电池/电源/电力设备","10021007","2","0"];
ctree[58] = ["其它","10021008","2","0"];
ctree[59] = ["居家日用/装饰/文具/园艺","1003","1","1"];
ctree[60] = ["布艺/床品/靠垫/窗帘","10031000","2","0"];
ctree[61] = ["时尚家饰","10031001","2","0"];
ctree[62] = ["家具","10031002","2","0"];
ctree[63] = ["洗浴/卫浴用品","10031003","2","0"];
ctree[64] = ["十字绣","10031004","2","0"];
ctree[65] = ["厨房及餐饮用品","10031005","2","0"];
ctree[66] = ["鲜花园艺","10031006","2","0"];
ctree[67] = ["工艺品","10031007","2","0"];
ctree[68] = ["生活日用","10031008","2","0"];
ctree[69] = ["文具/办公用品","10031009","2","0"];
ctree[70] = ["其它","10031010","2","0"];
ctree[71] = ["电脑/软件/网络/办公","1004","1","1"];
ctree[72] = ["电脑硬件","10041000","2","0"];
ctree[73] = ["笔记本电脑","10041001","2","0"];
ctree[74] = ["电脑周边","10041002","2","0"];
ctree[75] = ["办公设备","10041003","2","0"];
ctree[76] = ["笔记本配件","10041004","2","0"];
ctree[77] = ["台式电脑","10041005","2","0"];
ctree[78] = ["服务器/工作站/网络设备","10041006","2","0"];
ctree[79] = ["掌上电脑/PDA","10041007","2","0"];
ctree[80] = ["电子辞典/学习机","10041008","2","0"];
ctree[81] = ["电脑软件","10041009","2","0"];
ctree[82] = ["耗材/网线/刻录盘","10041010","2","0"];
ctree[83] = ["掌上电脑配件","10041011","2","0"];
ctree[84] = ["PDA掌上电脑软件","10041012","2","0"];
ctree[85] = ["其它","10041013","2","0"];
ctree[86] = ["手机/通讯设备/卡","1005","1","1"];
ctree[87] = ["手机","10051000","2","0"];
ctree[88] = ["手机配件","10051001","2","0"];
ctree[89] = ["手机饰品","10051002","2","0"];
ctree[90] = ["充值卡/手机卡/电话卡","10051003","2","0"];
ctree[91] = ["电话机及仪器","10051004","2","0"];
ctree[92] = ["手机服务/其它","10051005","2","0"];
ctree[93] = ["数码相机/摄像机/图形冲印","1006","1","1"];
ctree[94] = ["数码相机","10061000","2","0"];
ctree[95] = ["摄影类","10061001","2","0"];
ctree[96] = ["摄像类","10061002","2","0"];
ctree[97] = ["配件","10061003","2","0"];
ctree[98] = ["冲印/图形图像/摄影服务","10061004","2","0"];
ctree[99] = ["打印/冲印设备","10061005","2","0"];
ctree[100] = ["其它","10061006","2","0"];
ctree[101] = ["随身视听/音响/耳机","1007","1","1"];
ctree[102] = ["MP4","10071000","2","0"];
ctree[103] = ["MP3","10071001","2","0"];
ctree[104] = ["iPod随身听","10071002","2","0"];
ctree[105] = ["HIFI器材/音响设备","10071003","2","0"];
ctree[106] = ["耳机/耳麦","10071004","2","0"];
ctree[107] = ["便携视听","10071005","2","0"];
ctree[108] = ["电脑多媒体音箱","10071006","2","0"];
ctree[109] = ["其它","10071007","2","0"];
ctree[110] = ["彩妆/香水/护肤/美体","1008","1","1"];
ctree[111] = ["化妆品","10081000","2","0"];
ctree[112] = ["化妆棉/吸油纸/纸膜/湿纸巾","10081001","2","0"];
ctree[113] = ["化妆包/化妆箱","10081002","2","0"];
ctree[114] = ["化妆刷/化妆工具","10081003","2","0"];
ctree[115] = ["化妆镜/梳子","10081004","2","0"];
ctree[116] = ["彩妆","10081005","2","0"];
ctree[117] = ["瘦身纤体","10081006","2","0"];
ctree[118] = ["美发护发","10081007","2","0"];
ctree[119] = ["香水","10081008","2","0"];
ctree[120] = ["男士护理","10081009","2","0"];
ctree[121] = ["香精/精油","10081010","2","0"];
ctree[122] = ["其它","10081011","2","0"];
ctree[123] = ["运动/户外/休闲","1009","1","1"];
ctree[124] = ["运动用品/鞋/服","10091000","2","0"];
ctree[125] = ["健美、健身","10091001","2","0"];
ctree[126] = ["健身卡/会员卡/门票转让","10091002","2","0"];
ctree[127] = ["户外/野营用品","10091003","2","0"];
ctree[128] = ["户外军品专区","10091004","2","0"];
ctree[129] = ["天文/野营望远镜","10091005","2","0"];
ctree[130] = ["旅游/票务","10091006","2","0"];
ctree[131] = ["运动纪念品","10091007","2","0"];
ctree[132] = ["乐器","10091008","2","0"];
ctree[133] = ["体育书籍","10091009","2","0"];
ctree[134] = ["体育CD/VCD/DVD","10091010","2","0"];
ctree[135] = ["其它运动/休闲","10091011","2","0"];
var _select=document.getElementById("yxwplb0");
window.onload=function(){
for (i=0;i<ctree.length;i++)
{
if (ctree[i][2] == 1)
{
var newoption = new Option();
newoption.value = ctree[i][1]+","+ctree[i][3];
newoption.text = ctree[i][0];
_select.options.add(newoption);
}
}
}
function createcate(choosevalue){
this.choosevalue=choosevalue;
var _catecode=choosevalue.split(",")[0];
var _ischild=choosevalue.split(",")[1];
var _slength=_catecode.length;
var _sid=document.getElementById("catelist");
if (choosevalue.indexOf(",")==-1){deletesel(parseInt(choosevalue)+1);}
deletesel(_slength/4)
if(_ischild==1){
var _newselect = document.createElement("select");
_newselect.name="yxwplb";
_newselect.size="1";
_newselect.id="yxwplb"+_slength/4;
_newselect.onchange=function(){createcate(this.value)};
_newselect.options[0]= new Option("",""+_slength/4+"");
for(i=0;i<ctree.length;i++){
var _tempcate=ctree[i][1];
if(_tempcate.substr(0,_slength)==_catecode && ctree[i][2]==parseInt(_slength/4+1)){
var newoption = new Option();
newoption.value = ctree[i][1]+","+ctree[i][3];
newoption.text = ctree[i][0];
_newselect.options.add(newoption);
}
}
_sid.appendChild(_newselect);
}
}
function deletesel(selectid){
this.selectid=selectid;
for(i=selectid;i<maxdepth;i++ )
{
var _delselect=document.getElementById("yxwplb"+[i]);
if(_delselect!=null){
_delselect.removeNode(true);
}
}
}
</script>
</body>
</html>
ASP版
<%
sql="select a.*,(select max(depth) from category) as maxdepth from category a"
Set rs=conn.execute(sql)
If Not rs.eof Then
%>
<script language="javascript">
maxdepth = "<%=rs("maxdepth")%>";//类别最深度
var ctree = new Array();
//第一个值是类别名称,第二个值是类别ID,第三个值是类别深度,第四个值是个逻辑值,看是否有下级
var heihei_id = new Array();
<%
i=0
While Not rs.eof
%>
ctree[<%=i%>] = ["<%=rs(1)%>","<%=rs(2)%>","<%=rs(4)%>","<%=rs(5)%>"];
<%
i=i+1
rs.movenext
wend
%>
var _select=document.getElementById("yxwplb0");
window.onload=function(){
for (i=0;i<ctree.length;i++)
{
if (ctree[i][2] == 1)
{
var newoption = new Option();
newoption.value = ctree[i][1]+","+ctree[i][3];
newoption.text = ctree[i][0];
_select.options.add(newoption);
}
}
}
function createcate(choosevalue){
this.choosevalue=choosevalue;
var _catecode=choosevalue.split(",")[0];
var _ischild=choosevalue.split(",")[1];
var _slength=_catecode.length;
var _sid=document.getElementById("catelist");
if (choosevalue.indexOf(",")==-1){deletesel(parseInt(choosevalue)+1);}
deletesel(_slength/4)
if(_ischild==1){
var _newselect = document.createElement("select");
_newselect.name="yxwplb";
_newselect.size="1";
_newselect.id="yxwplb"+_slength/4;
_newselect.onchange=function(){createcate(this.value)};
_newselect.options[0]= new Option("",""+_slength/4+"");
for(i=0;i<ctree.length;i++){
var _tempcate=ctree[i][1];
if(_tempcate.substr(0,_slength)==_catecode && ctree[i][2]==parseInt(_slength/4+1)){
var newoption = new Option();
newoption.value = ctree[i][1]+","+ctree[i][3];
newoption.text = ctree[i][0];
_newselect.options.add(newoption);
}
}
_sid.appendChild(_newselect);
}
}
function deletesel(selectid){
this.selectid=selectid;
for(i=selectid;i<maxdepth;i++ )
{
var _delselect=document.getElementById("yxwplb"+[i]);
if(_delselect!=null){
_delselect.removeNode(true);
}
}
}
</script>
<%
End If
rs.close
Set rs=Nothing
Set Conn=Nothing
%>
catename 类别名称
catecode 类别ID
cateintro 类别介绍
depth 类别深度
childid 逻辑值 1:有子类,0没有
isproperty 逻辑值 1:有属性,0没有
pcount 该类产品对应的总量