<script>
<!--
<%
'二级数据保存到数组
Dim count2,cityRS,citySQL
set cityRS=server.createobject("adodb.recordset")
citySQL="select * from sys_city"
cityRS.open citySQL,conn,1,1
%>
var subval2 = new Array();
//数组结构:一级根值,二级根值,二级显示值
<%
count2 = 0
do while not cityRS.eof
%>
subval2[<%=count2%>] = new Array('<%=cityRS("provinceid")%>','<%=cityRS("id")%>','<%=cityRS("cityname")%>')
<%
count2 = count2 + 1
cityRS.movenext
loop
cityRS.close
%>
<%
'三级数据保存到数组
Dim count3,townRS,townSQL
set townRS=server.createobject("adodb.recordset")
townSQL="select * from sys_town"
townRS.open townSQL,conn,1,1
%>
var subval3 = new Array();
//数组结构:二级根值,三级根值,三级显示值
<%
count3 = 0
do while not townRS.eof
%>
subval3[<%=count3%>] = new Array('<%=townRS("cityid")%>','<%=townRS("ID")%>','<%=townRS("townname")%>')
<%
count3 = count3 + 1
townRS.movenext
loop
townRS.close
%>
function changeselect1(locationid)
{
document.form1.cityID.length = 0;
document.form1.cityID.options[0] = new Option('请选择城市','');
document.form1.townID.length = 0;
document.form1.townID.options[0] = new Option('请选择城区','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.cityID.options[document.form1.cityID.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}function changeselect2(locationid)
{
document.form1.townID.length = 0;
document.form1.townID.options[0] = new Option('请选择城区','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{document.form1.townID.options[document.form1.townID.length] = new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>
<form id="form1" name="form1" method="post" action="">
<%
Dim count1,provinceRS,provinceSQL
set provinceRS=server.createobject("adodb.recordset")
provinceSQL="select * from sys_province order by orderfield"
provinceRS.open provinceSQL,conn,1,1
%> <select name="provinceID" id="provinceID" onChange="changeselect1(this.value)">
<option value="">请选择省份</option>
<%
do while not provinceRS.eof
response.Write "<option value="&provinceRS("ID")&">"&provinceRS("provincename")&"</option>"
provinceRS.movenext
loop
provinceRS.close
set provinceRS = nothing
%>
</select>
<select name="cityID" id="cityID" onChange="changeselect2(this.value)">
<option value="">请选择城市</option>
</select>
<select name="townID" id="townID">
<option value="">请选择城区</option>
</select>
</form>
<!--
<%
'二级数据保存到数组
Dim count2,cityRS,citySQL
set cityRS=server.createobject("adodb.recordset")
citySQL="select * from sys_city"
cityRS.open citySQL,conn,1,1
%>
var subval2 = new Array();
//数组结构:一级根值,二级根值,二级显示值
<%
count2 = 0
do while not cityRS.eof
%>
subval2[<%=count2%>] = new Array('<%=cityRS("provinceid")%>','<%=cityRS("id")%>','<%=cityRS("cityname")%>')
<%
count2 = count2 + 1
cityRS.movenext
loop
cityRS.close
%>
<%
'三级数据保存到数组
Dim count3,townRS,townSQL
set townRS=server.createobject("adodb.recordset")
townSQL="select * from sys_town"
townRS.open townSQL,conn,1,1
%>
var subval3 = new Array();
//数组结构:二级根值,三级根值,三级显示值
<%
count3 = 0
do while not townRS.eof
%>
subval3[<%=count3%>] = new Array('<%=townRS("cityid")%>','<%=townRS("ID")%>','<%=townRS("townname")%>')
<%
count3 = count3 + 1
townRS.movenext
loop
townRS.close
%>
function changeselect1(locationid)
{
document.form1.cityID.length = 0;
document.form1.cityID.options[0] = new Option('请选择城市','');
document.form1.townID.length = 0;
document.form1.townID.options[0] = new Option('请选择城区','');
for (i=0; i<subval2.length; i++)
{
if (subval2[i][0] == locationid)
{document.form1.cityID.options[document.form1.cityID.length] = new Option(subval2[i][2],subval2[i][1]);}
}
}function changeselect2(locationid)
{
document.form1.townID.length = 0;
document.form1.townID.options[0] = new Option('请选择城区','');
for (i=0; i<subval3.length; i++)
{
if (subval3[i][0] == locationid)
{document.form1.townID.options[document.form1.townID.length] = new Option(subval3[i][2],subval3[i][1]);}
}
}
//-->
</script>
<form id="form1" name="form1" method="post" action="">
<%
Dim count1,provinceRS,provinceSQL
set provinceRS=server.createobject("adodb.recordset")
provinceSQL="select * from sys_province order by orderfield"
provinceRS.open provinceSQL,conn,1,1
%> <select name="provinceID" id="provinceID" onChange="changeselect1(this.value)">
<option value="">请选择省份</option>
<%
do while not provinceRS.eof
response.Write "<option value="&provinceRS("ID")&">"&provinceRS("provincename")&"</option>"
provinceRS.movenext
loop
provinceRS.close
set provinceRS = nothing
%>
</select>
<select name="cityID" id="cityID" onChange="changeselect2(this.value)">
<option value="">请选择城市</option>
</select>
<select name="townID" id="townID">
<option value="">请选择城区</option>
</select>
</form>
我这有个例子,我想给你发上去,但是这是连接数据库的,
不好意思了楼主,,
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array("ASP基础","1","1");
subcat[1] = new Array("ASP应用","1","2");
subcat[2] = new Array("ASP技巧","1","3");
subcat[3] = new Array("性能优化","2","4");
subcat[4] = new Array("安全加密","2","5");
subcat[5] = new Array("XML相关","2","6");
subcat[6] = new Array("全文检索","3","7");
subcat[7] = new Array("客户端相关","3","8");
subcat[8] = new Array("打印相关","3","9");
subcat[9] = new Array("数据库相关","4","10");
subcat[10] = new Array("入门教程","4","11");
subcat[11] = new Array("FTP/HTTP/Debug","4","12");
onecount=12;
function changelocation(locationid)
{
document.myform.Nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{ if (subcat[i][1] == locationid)
{ document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]); } } }
</script>
<form method="post" name="myform" action="ru_query.asp">
<select name="classid" onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" size="1">
<option selected value="">未指定条件</option>
<option value="1">.Net专区</option>
<option value="2">ASP技术</option>
<option value="3">PHP技术</option>
<option value="4">JSP技术</option>
</select>
<select name="Nclassid">
<option selected value="">未指定条件</option>
</select>
</form>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array("ASP基础","1","1");
subcat[1] = new Array("ASP应用","1","2");
subcat[2] = new Array("ASP技巧","1","3");
subcat[3] = new Array("性能优化","2","4");
subcat[4] = new Array("安全加密","2","5");
subcat[5] = new Array("XML相关","2","6");
subcat[6] = new Array("全文检索","3","7");
subcat[7] = new Array("客户端相关","3","8");
subcat[8] = new Array("打印相关","3","9");
subcat[9] = new Array("数据库相关","4","10");
subcat[10] = new Array("入门教程","4","11");
subcat[11] = new Array("FTP/HTTP/Debug","4","12");
onecount=12;
function changelocation(locationid)
{
document.myform.Nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{ if (subcat[i][1] == locationid)
{ document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]); } } }
var ccc;
ccc=0;
hhh = new Array();
hhh[0] = new Array("1","1","1");
hhh[1] = new Array("2","1","2");
hhh[2] = new Array("3","1","3");
hhh[3] = new Array("4","2","4");
hhh[4] = new Array("安全加密","2","5");
hhh[5] = new Array("XML相关","2","6");
hhh[6] = new Array("全文检索","3","7");
hhh[7] = new Array("客户端相关","3","8");
hhh[8] = new Array("打印相关","3","9");
hhh[9] = new Array("数据库相关","4","10");
hhh[10] = new Array("入门教程","4","11");
hhh[11] = new Array("FTP/HTTP/Debug","4","12");
ccc=12;
function changelocation(bbb)
{
document.myform.aaa.length = 0;
var bbb=bbb;
var a;
for (a=0;a < ccc; a++)
{ if (hhh[a][1] == bbb)
{ document.myform.aaa.options[document.myform.aaa.length] = new Option(hhh[a][0], hhh[a][2]); } } }
</script>
<form method="post" name="myform" action="ru_query.asp">
<select name="classid" onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" size="1">
<option selected value="">未指定条件</option>
<option value="1">.Net专区</option>
<option value="2">ASP技术</option>
<option value="3">PHP技术</option>
<option value="4">JSP技术</option>
</select>
<select name="Nclassid">
<option selected value="">未指定条件</option>
</select>
<select name="aaa">
<option selected value="">未指定条件</option>
</select>
</form>
<script language = "JavaScript">
var onecount;
onecount=0;
subcat = new Array();
subcat[0] = new Array("ASP基础","1","1");
subcat[1] = new Array("ASP应用","1","2");
subcat[2] = new Array("ASP技巧","1","3");
subcat[3] = new Array("性能优化","2","4");
subcat[4] = new Array("安全加密","2","5");
subcat[5] = new Array("XML相关","2","6");
subcat[6] = new Array("全文检索","3","7");
subcat[7] = new Array("客户端相关","3","8");
subcat[8] = new Array("打印相关","3","9");
subcat[9] = new Array("数据库相关","4","10");
subcat[10] = new Array("入门教程","4","11");
subcat[11] = new Array("FTP/HTTP/Debug","4","12");
onecount=12;
function changelocation(locationid)
{
document.myform.Nclassid.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{ if (subcat[i][1] == locationid)
{ document.myform.Nclassid.options[document.myform.Nclassid.length] = new Option(subcat[i][0], subcat[i][2]);
}
} document.myform.Nclassid2.length = 0;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{ if (subcat[i][1] == locationid)
{
document.myform.Nclassid2.options[document.myform.Nclassid2.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
</script>
<form method="post" name="myform" action="ru_query.asp">
<select name="classid" onChange="changelocation(document.myform.classid.options[document.myform.classid.selectedIndex].value)" size="1">
<option selected value="">未指定条件 </option>
<option value="1">.Net专区 </option>
<option value="2">ASP技术 </option>
<option value="3">PHP技术 </option>
<option value="4">JSP技术 </option>
</select>
<select name="Nclassid">
<option selected value="">未指定条件 </option>
</select>
<select name="Nclassid2">
<option selected value="">未指定条件 </option>
</select>
</form>
<body>
<div id='ss'></div>
<script>
var a =[[1,2,3],[11,22,33],[111,222,333]];
var title=["标题1","标题2","标题3"];
var length =3;
function $(Id){return document.getElementById(Id)}
function addListener(element,e,fn){ element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn)};
function create(elm,parent,fn){
var element = document.createElement(elm);
if(fn)fn(element)
parent.appendChild(element);
}
function hh(num){
$('ss').getElementsByTagName("select")[1].selectedIndex=num
$('ss').getElementsByTagName("select")[2].selectedIndex=num
}function initialize(){
for(var i = 0; i<length;i++){
$('ss').innerHTML=$('ss').innerHTML+title[i];
create('select',$('ss'),function(obj){
for(var j = 0;j<a.length;j++)
{
obj.options.add(new Option(a[i][j],j))
var ss =obj
}
})
}
addListener($('ss').getElementsByTagName("select")[0],'change',function(){hh($('ss').getElementsByTagName("select")[0].selectedIndex)})
}
initialize()
</script>
</body>
<select name="cityID" id="cityID" onChange="changeselect();">
<option value="1">beijing</option>
<option value="2">shanghai</option>
</select>
<select name="townID" id="townID">
<option value="1">shangdi</option>
<option value="2">pudong</option>
</select>
<select name="man" id="man">
<option value="1">beijingman</option>
<option value="2">shanghailady</option>
</select>
</form>
<SCRIPT language=JavaScript>
function changeselect() {
if(document.form1.cityID.value=='1'){
document.form1.townID.value='1';
document.form1.man.value='1';
} else if (document.form1.cityID.value=='2'){
document.form1.townID.value='2';
document.form1.man.value='2';
}
}</SCRIPT>
是要的这种效果??