日期:2014-05-17  浏览次数:20742 次

谁能帮我写一个简单的二级联动的JS程序??立即结分。
在网上搜了一下,没有看懂,也没有改出来。
没学过C系统的语法,想学习一下(如果有注释最好。)

系部和专业联动的表。
access数据库结构如下:


表1:
表名为:xibu
所有字段为:x_id,x_name


表2
表名为:zhuanye
所有字段为:z_id,z_name,x_id

不知道这样清楚了没有。谢谢!


------解决方案--------------------
<script language= "JavaScript ">
<!--
<%
'二级数据保存到数组
Dim count2,midRS,midSQL
set midRS=server.createobject( "adodb.recordset ")
midSQL= "select * from zhuanye "
midRS.open midSQL,conn,1,1
%>
var subval2 = new Array();
//数组结构:一级根值,二级根值,二级显示值
<%
count2 = 0
do while not midRS.eof
%>
subval2[ <%=count2%> ] = new Array( ' <%=midRS( "x_id ")%> ', ' <%=midRS( "z_id ")%> ', ' <%=midRS( "z_name ")%> ')
<%
count2 = count2 + 1
midRS.movenext
loop
midRS.close
%>
function changeselect1(locationid)
{
document.form1.midClass.length = 0;
document.form1.midClass.options[0] = new Option( '==请选择专业== ', ' ');

for (i=0; i <subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.midClass.options[document.form1.midClass.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}
<form id= "form1 " name= "form1 " method= "post " action= " ">
<%
Dim count1,bigRS,bigSQL
set bigRS=server.createobject( "adodb.recordset ")
bigSQL= "select * from xibu "
bigRS.open bigSQL,conn,1,1
%>
<select name= "bigClass " id= "bigClass " onChange= "changeselect1(this.value) ">
<option> ==请选择大类== </option>
<%
count1 = 0
do while not bigRS.eof
%>
<option value= " <%=bigRS( "x_id ")%> "> <%=bigRS( "x_name ")%> </option> "
<%
count1 = count1 + 1
bigRS.movenext
loop
bigRS.close
%>
</select>
<select name= "midClass " id= "midClass " onChange= "changeselect2(this.value) ">
<option> ==请选择中类== </option>
</form>