`

无刷新三级联动菜单从数据库获取数据(适用于firefox和ie)

阅读更多
表单叶面
<scriptlanguage="javascript"src="include/selectoption.js"></script>

<selectname="privceid"id="privceid"onchange="editnextselect(this,'cityid');">
<optionvalue="-1">请选择</option>
</select>
<selectname="cityid"id="cityid"onchange="editnextselect(this,'county');">
<optionvalue="-1">请选择</option>
</select>
<selectname="county"id="county">
<optionvalue="-1">请选择</option>
</select>区/县

<scriptlanguage="javascript">...
varprivceid="<%=privceid%>";
varcityid="<%=cityid%>";
varcounty="<%=county%>";
getdatelist(
'&pid=',privceid,'privceid');
if(cityid!="")...{getdatelist('&pid='+privceid,cityid,'cityid');}
if(county!="")...{getdatelist('&pid='+cityid,county,'county');}
functioneditnextselect(obj,nexselid)...{
if(nexselid=='cityid')...{
selvalue
=cityid;
}
else...{
selvalue
=county;
}

varpid=obj.options[obj.selectedIndex].value;
if(pid!=null)...{
getdatelist(
'&pid='+pid,selvalue,nexselid);
}

}

</script>
js包含叶面
//JavaScriptDocument
functionInitAjax()...{
varajax=false;
try...{ajax=newActiveXObject("Msxml2.XMLHTTP");}
catch(e)...{
try...{ajax=newActiveXObject("Microsoft.XMLHTTP");}
catch(E)...{ajax=false;}
}

if(!ajax&&typeofXMLHttpRequest!='undefined')...{ajax=newXMLHttpRequest();}
returnajax;
}

functiondatexml(url,value)...{
varnumber=Math.random();
 
varurl=url+"?qaaq="+number+value;
 
varajax=InitAjax();
 ajax.open(
"GET",url,false);
 ajax.send(
null);
//ajax.onreadystatechange=function(){}
 if(ajax.readyState==4&&ajax.status==200)...{returnajax.responseText;}
}

functiongetdatelist(values,selvalues,SelectName)...{
vargetdate=datexml("include/xmlgetp_c_c.asp",values);
if(getdate)...{
if(getdate!="wrong"&&getdate!="no")...{
varobjSelect=document.getElementById(SelectName);
objSelect.options.length
=1;
vardatearray=getdate.split("$");
for(i=0;i<datearray.length-1;i++)...{
varop=window.document.createElement("option");
op.value
=datearray[i].split("|")[0];
op.innerHTML
=unescape(datearray[i].split("|")[1]);
objSelect.appendChild(op);
}

if(selvalues!="")...{
for(i=0;i<objSelect.options.length;i++)...{
if(objSelect.options[i].value==selvalues)...{
objSelect.options[i].selected
=true;
break;
}

}

}

}

}

}

读取数据库叶面
<!--#includefile="dbconn.asp"-->
<%
pid
=request.querystring("pid")
ifpid<>""then
ifisnumeric(pid)=falsethen
response.write
"wrong"
endif
endif
ifpid=""then
sql
="selectzipcode,zipnamefromZIPCODEINFOwhereparentzipisnull"
else
sql
="selectzipcode,zipnamefromzipcodeinfowhereparentzip='"&pid&"'"
endif
calldbopen
setrs=conn.execute(sql)
ifnotrs.eofthen
dowhilenotrs.eof
response.writers(
"zipcode")&"|"&escape(rs("zipname"))&"$"
rs.movenext
loop
else
response.write
"no"
endif
setrs=nothing
calldbclose
%
>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics