網(wǎng)上三級菜單多是多但是代碼都比較煩,我這個(gè)應(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>"
%>
復(fù)制代碼 代碼如下:
!-- 三級聯(lián)動(dòng)菜單 開始 -->
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();
//數(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; isubval2.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; isubval3.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">
三級聯(lián)動(dòng):
%
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)動(dòng)菜單 結(jié)束 -->
您可能感興趣的文章:- PHP+Mysql+Ajax+JS實(shí)現(xiàn)省市區(qū)三級聯(lián)動(dòng)
- JS制作簡單的三級聯(lián)動(dòng)
- javascript實(shí)現(xiàn)省市區(qū)三級聯(lián)動(dòng)下拉框菜單
- 省市區(qū)三級聯(lián)動(dòng)下拉框菜單javascript版
- jquery+json 通用三級聯(lián)動(dòng)下拉列表
- js實(shí)現(xiàn)一個(gè)省市區(qū)三級聯(lián)動(dòng)選擇框代碼分享
- js實(shí)現(xiàn)三級聯(lián)動(dòng)效果(簡單易懂)
- 原生js三級聯(lián)動(dòng)的簡單實(shí)現(xiàn)代碼
- 從QQ網(wǎng)站中提取的純JS省市區(qū)三級聯(lián)動(dòng)菜單
- JavaScript實(shí)現(xiàn)省市區(qū)三級聯(lián)動(dòng)