梦幻西游代言人:级联菜单问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 11:09:50
请大家看看下面这段代码哪里出错??
同样是下面的代码我挪动了一下地方,原码一点没变却提示有错,
<script language="JavaScript" type="text/javascript">
<!--
//cache用于存储已经获取的数据
var cache=[];
function getLevel2(){
if(document.forms.ws.province.selectedIndex==0){
//当一级菜单未选中时,二级菜单仅保留提示项
document.forms.ws.city.length=1;
return;
}
//如果当前二级分类没有被缓存,则从服务器端获取
if(!cache[document.forms.ws.province.selectedIndex]){
//建立跨浏览器的XMLHttpRequest对象
var xmlhttp;
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
//创建请求,并使用escape对userName编码,以避免乱码
xmlhttp.open("get","ajax.asp?id="+document.forms.ws.province.value);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
cache[document.forms.ws.province.selectedIndex]=eval("("+unescape(xmlhttp.responseText)+")");
//获取成功后重新调用getLevel2,将数据填充到下拉框,如果直接在这里写会造成代码重复
getLevel2();
}else{
alert("网络失败。");
}
}
}
xmlhttp.send(null);
//必须在这里返回,等待回调
return;
}
//此时已经确保缓存不为空
document.forms.ws.city.length=0;
var _arr=cache[document.forms.ws.province.selectedIndex];
for(var i=0;i<_arr.length-1;i+=2){
with(document.forms.ws.city){
options[options.length]=new Option(_arr[i],_arr[i+1]);
}
}
}
//-->
</script>
在这里调用
<form name="ws">
<select name="province" onChange="getLevel2()">
<option value="0">请选择一级分类:</option>
<%
'遍历记录集生成下拉菜单选项
while not rs.eof
Response.write("<option value='" & rs("id") & "'>")
Response.write(rs("classname"))
Response.write("</option>")
rs.movenext
wend
'关闭数据库连接及记录集,释放资源
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
</select>
<select name="city">
<option value="0">请选择二级分类:</option>
</select>
</form>

怎么提示得?