網(wǎng)上三級菜單多是多但是代碼都比較煩,我這個應(yīng)該說還是比較直觀的:
========================================================
'肯定先要連接數(shù)據(jù)庫了,不用說了
'數(shù)據(jù)庫結(jié)構(gòu)
'類別1表名稱:a字段:ID,Name說明:ID為主鍵是類別1的ID值,Name為類別1的名稱
'類別2表名稱:aa字段:ID,aID,Name說明:ID為主鍵是類別2的ID值,aID為所屬類別1的ID值,Name為類別2的名稱
'類別3表名稱:aaa字段:ID,aID,aaID,Name說明:ID為主鍵是類別3的ID值,aID為所屬類別1的ID值,aaID為所屬類別2的ID值,Name為類別3的名稱
=====test1.asp 你可以測試下,接收到的都是類別的ID值====
<%
response.write"1:"&Request.form("s1")&"<BR>"
response.write"2:"&Request.form("s2")&"<BR>"
response.write"3:"&Request.form("s3")&"<BR>"
%>
=========================================================
<!-- 三級聯(lián)動菜單 開始 -->
<script language="JavaScript">
<!--
<%
'二級數(shù)據(jù)保存到數(shù)組
Dim count2,rsClass2,sqlClass2
set rsClass2=server.createobject("adodb.recordset")
sqlClass2="select * from aa"
rsClass2.open sqlClass2,conn,1,1
%>
var subval2 = new Array();
伊圖教程網(wǎng)[www.etoow.com]
http://www.etoow.com/html/2007-02/1170469109.html
//數(shù)組結(jié)構(gòu):一級根值,二級根值,二級顯示值
<%
count2 = 0
do while not rsClass2.eof
%>
subval2[<%=count2%>] = new Array('<%=rsClass2("aID")%>','<%=rsClass2("ID")%>','<%=rsClass2("Name")%>')
<%
count2 = count2 + 1
rsClass2.movenext
loop
rsClass2.close
%>
<%
'三級數(shù)據(jù)保存到數(shù)組
Dim count3,rsClass3,sqlClass3
set rsClass3=server.createobject("adodb.recordset")
sqlClass3="select * from aaa"
rsClass3.open sqlClass3,conn,1,1
%>
var subval3 = new Array();
//數(shù)組結(jié)構(gòu):二級根值,三級根值,三級顯示值
<%
count3 = 0
do while not rsClass3.eof
%>
subval3[<%=count3%>] = new Array('<%=rsClass3("aaID")%>','<%=rsClass3("ID")%>','<%=rsClass3("Name")%>')
<%
count3 = count3 + 1
rsClass3.movenext
loop
rsClass3.close
%>
function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option('==請選擇類別==','');
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==請選擇專題==','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.s2.options[document.form1.s2.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}
function changeselect2(locationid)
{
document.form1.s3.length = 0;
document.form1.s3.options[0] = new Option('==請選擇專題==','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{document.form1.s3.options[document.form1.s3.length] = new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>
<form name="form1" method="post" action="test1.asp">
伊圖教程網(wǎng)[www.etoow.com]
http://www.etoow.com/html/2007-02/1170469109-1.html
三級聯(lián)動:
<%
Dim count1,rsClass1,sqlClass1
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from a"
rsClass1.open sqlClass1,conn,1,1
%>
<select name="s1" onChange="changeselect1(this.value)">
<option>==請選擇頻道==</option>
<%
count1 = 0
do while not rsClass1.eof
response.write"<option value="&rsClass1("ID")&">"&rsClass1("Name")&"</option>"
count1 = count1 + 1
rsClass1.movenext
loop
rsClass1.close
%>
</select>
<select name="s2"onChange="changeselect2(this.value)">
<option>==請選擇類別==</option>
</select>
<select name="s3">
<option>==請選擇專題==</option>
</select>
<input type="submit" name="Submit" value="提交"></form>
<!-- 三級聯(lián)動菜單 結(jié)束 -->
更多信息請查看IT技術(shù)專欄