求一三级联动JS代码

<!--#includefile="check.asp"--><%dimcountsetps=server.createobject("adodb.recordset")... <!--#include file="check.asp"-->
<%dim count
set ps=server.createobject("adodb.recordset")
ps.open "select * from smallclass",conn,1,1%>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
<%
count = 0
do while not ps.eof
%>
subcat[<%=count%>] = new Array("<%= trim(ps("smallclass"))%>","<%= ps("bigclassid")%>","<%= ps("smallclassid")%>");
<%
count = count + 1
ps.movenext
loop
ps.close
%>

onecount=<%=count%>;

function changelocation(locationid)
{
document.myform.smallclassid.length = 0;

var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.smallclassid.options[document.myform.smallclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
}

}
</script>
<%
ps.open "select * from bigclass",conn,1,1
if ps.eof and ps.bof then%>
<font color="#FF0000">请先添加栏目</font>
<%response.end
else
%>
一级信息:
<select name="bigclassid" size="1" id="bigclassid" onChange="changelocation(document.myform.bigclassid.options[document.myform.bigclassid.selectedIndex].value)">
<option selected value="<%=ps("bigclassid")%>"><%=trim(ps("bigclass"))%></option>
<% dim selclass
selclass=ps("bigclassid")
ps.movenext
do while not ps.eof
%>
<option value="<%=ps("bigclassid")%>"><%=trim(ps("bigclass"))%></option>
<%
ps.movenext
loop
end if
ps.close
%>
</select>
二级信息:
<select name="smallclassid">
<%ps.open "select * from smallclass where bigclassid="&selclass ,conn,1,1
if not(ps.eof and ps.bof) then
%>
<option selected value="<%=ps("smallclassID")%>"><%=ps("smallclass")%></option>
<% ps.movenext
do while not ps.eof%>
<option value="<%=ps("smallclassID")%>"><%=ps("smallclass")%></option>
<% ps.movenext
loop
end if
ps.close
set ps = nothing
%>
</select>
如何将这个二级改成三级联动?
展开
 我来答
cari_ayong
2006-10-17 · TA获得超过207个赞
知道小有建树答主
回答量:168
采纳率:0%
帮助的人:147万
展开全部
<form method="post" name="myform">
<select name="classid" onchange="select()"></select>
<select name="suid"></select>
<select name="gid"></select>
</form>
<script language="javascript">
<!--
var arrText = new Array(5);
var arrValue = new Array(arrText.length);

function objSetOption(select1, select2, select3) {
this.select1 = select1;
this.select2 = select2;
this.select3 = select3;
}

arrText[0]= new objSetOption("选择1:", "选择2_1:,选择2_2:", "选择3_1:,选择3_2:");
arrText[1] = new objSetOption("论文:1", "语文:1,数学:2,英语:3", "初中:2,高中:3");
arrText[2] = new objSetOption("例题:2", "显示b2_1:值b2_1,显示b2_2:值b2_2", "显示b3_1:值b3_1,显示b3_2:值b3_2");
arrText[3] = new objSetOption("显示c:值c", "显示c2_1:值c2_1,显示c2_2:值c2_2", "显示c3_1:值c3_1,显示c3_2:值c3_2");
arrText[4] = new objSetOption("显示d:值d", "显示d2_1:值d2_1,显示d2_2:值d2_2", "显示d3_1:值d3_1,显示d3_2:值d3_2");
arrText[5] = new objSetOption("显示e:值e", "显示e2_1:值e2_1,显示e2_2:值e2_2", "显示e3_1:值e3_1,显示e3_2:值e3_2");

function select(sValue1, sValue2, sValue3) {
var eltSelect1 = document.myform.classid;
var eltSelect2 = document.myform.suid;
var eltSelect3 = document.myform.gid;
var arrSelect1, arrSelect2, arrSelect3;
var arrData1, arrData2, arrData3;
with(eltSelect1) {
var strSelect = options[selectedIndex].value;
}
for(i = 0;i < arrText.length;i ++) {
arrSelect1 = arrText[i].select1;
arrData1 = arrSelect1.split(":");
if (arrData1[1] == strSelect) {
arrSelect2 = (arrText[i].select2).split(",");
for(j = 0;j < arrSelect2.length;j++) {
arrData2 = arrSelect2[j].split(":");
with(eltSelect2) {
length = arrSelect2.length;
options[j].text = arrData2[0];
options[j].value = arrData2[1];
if (arrData2[1] == sValue2) {
options[j].selected = true;
}
}
}
arrSelect3 = (arrText[i].select3).split(",");
for(j = 0;j < arrSelect3.length;j++) {
arrData3 = arrSelect3[j].split(":");
with(eltSelect3) {
length = arrSelect3.length;
options[j].text = arrData3[0];
options[j].value = arrData3[1];
if (arrData3[1] == sValue3) {
options[j].selected = true;
}
}
}
break;
}
}
}

function init(sValue1, sValue2, sValue3) {
var eltSelect1 = document.myform.classid;
var eltSelect2 = document.myform.suid;
var eltSelect3 = document.myform.gid;
var arrSelect1, arrSelect2, arrSelect3;
var arrData1, arrData2, arrData3;
if (eltSelect1 != undefined && eltSelect2 != undefined && eltSelect3 != undefined) {
with(eltSelect2) {
arrSelect2 = (arrText[0].select2).split(",");
length = arrSelect2.length;
for(i = 0;i < length;i ++) {
arrData2 = arrSelect2[i].split(":");
options[i].text = arrData2[0];
options[i].value = arrData2[1];
}
}
with(eltSelect3) {
arrSelect3 = (arrText[0].select3).split(",");
length = arrSelect3.length;
for(i = 0;i < length;i ++) {
arrData3 = arrSelect3[i].split(":");
options[i].text = arrData3[0];
options[i].value = arrData3[1];
}
}
with(eltSelect1) {
length = arrText.length;
for(i = 0;i < arrText.length;i ++) {
arrSelect1 = arrText[i].select1;
arrData1 = arrSelect1.split(":");
options[i].text = arrData1[0];
options[i].value = arrData1[1];
if (arrData1[1] == sValue1) {
options[i].selected = true;
select("", sValue2, sValue3);
}
}
}
}
}

//init();
//默认初始化

init("2", "值b2_1", "值b3_2");
//更改后默认初始化
// -->
</script>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式