在网上下了个三级的联动菜单,一个页面只能用一次,用二次就不行
function Dsy(){this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
<%
sub province() '省份
dim rsa,pro,i
set rsa = conn.execute("select * from Chinasj_Province order by px asc,id asc")
If not Rsa.Eof then
i = 1
do while not rsa.eof
pro = pro & (""""&Rsa("Province")&""",")
Call city(rsa("ProvinceID"),Cstr(i)-1)
i = i + 1
rsa.movenext
loop
Response.Write ("dsy.add(""0"",[")
Response.Write mid(pro,1,len(pro)-1)
Response.Write ("]);")&vbcrlf
End If
end sub
sub city(provinceID,pid) '市
dim rsb,cit,i
set rsb = conn.execute("select * from Chinasj_city where father='"&provinceID&"' order by px asc,id asc")
If not rsb.Eof then
i = 1
do while not rsb.eof
cit = cit & (""""&rsb("city")&""",")
Call area(rsb("cityid"),pid,i-1) '
i = i + 1
rsb.movenext
loop
Response.Write ("dsy.add(""0_"&pid&""",[")
Response.Write mid(cit,1,len(cit)-1)
Response.Write ("]);")&vbcrlf
End If
end sub
sub area(cityid,pid,cid) '县
dim rsc,ara
set rsc = conn.execute("select * from Chinasj_area where father='"&cityid&"' order by px asc,id asc")
If not rsc.Eof then
do while not rsc.eof
ara = ara & (""""&rsc("area")&""",")
rsc.movenext
loop
Response.Write ("dsy.add(""0_"&pid&"_"&cid&""",[")
Response.Write mid(ara,1,len(ara)-1)
Response.Write ("]);")&vbcrlf
End If
end sub
%>
<% call province()%>
var s=["s1","s2","s3"];
var opt0 = ["省份...","地级市...","市、县级市、县..."];
function setup()
{
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}因为我要同一个页面中用三处,不知道怎么弄?感激不尽!
[[it] 本帖最后由 chinasj 于 2008-4-26 22:08 编辑 [/it]]