问题描述
如何实现简单的三级联动效果?数据时从表中读取的。兼容性要好的,我目前实现的这个好多浏览器不兼容。。。。
解决方案
解决方案二:
<script><!--<%'二级数据保存到数组Dimcount2,cityRS,citySQLsetcityRS=server.createobject("adodb.recordset")citySQL="select*fromsys_city"cityRS.opencitySQL,conn,1,1%>varsubval2=newArray();//数组结构:一级根值,二级根值,二级显示值<%count2=0dowhilenotcityRS.eof%>subval2[<%=count2%>]=newArray('<%=cityRS("provinceid")%>','<%=cityRS("id")%>','<%=cityRS("cityname")%>')<%count2=count2+1cityRS.movenextloopcityRS.close%><%'三级数据保存到数组Dimcount3,townRS,townSQLsettownRS=server.createobject("adodb.recordset")townSQL="select*fromsys_town"townRS.opentownSQL,conn,1,1%>varsubval3=newArray();//数组结构:二级根值,三级根值,三级显示值<%count3=0dowhilenottownRS.eof%>subval3[<%=count3%>]=newArray('<%=townRS("cityid")%>','<%=townRS("ID")%>','<%=townRS("townname")%>')<%count3=count3+1townRS.movenextlooptownRS.close%>functionchangeselect1(locationid){document.form1.cityID.length=0;document.form1.cityID.options[0]=newOption('请选择城市','');document.form1.townID.length=0;document.form1.townID.options[0]=newOption('请选择城区','');for(i=0;i<subval2.length;i++){if(subval2[i][0]==locationid){document.form1.cityID.options[document.form1.cityID.length]=newOption(subval2[i][2],subval2[i][1]);}}}functionchangeselect2(locationid){document.form1.townID.length=0;document.form1.townID.options[0]=newOption('请选择城区','');for(i=0;i<subval3.length;i++){if(subval3[i][0]==locationid){document.form1.townID.options[document.form1.townID.length]=newOption(subval3[i][2],subval3[i][1]);}}}//--></script><formid="form1"name="form1"method="post"action=""><%Dimcount1,provinceRS,provinceSQLsetprovinceRS=server.createobject("adodb.recordset")provinceSQL="select*fromsys_provinceorderbyorderfield"provinceRS.openprovinceSQL,conn,1,1%><selectname="provinceID"id="provinceID"onChange="changeselect1(this.value)"><optionvalue="">请选择省份</option><%dowhilenotprovinceRS.eofresponse.Write"<optionvalue="&provinceRS("ID")&">"&provinceRS("provincename")&"</option>"provinceRS.movenextloopprovinceRS.closesetprovinceRS=nothing%></select><selectname="cityID"id="cityID"onChange="changeselect2(this.value)"><optionvalue="">请选择城市</option></select><selectname="townID"id="townID"><optionvalue="">请选择城区</option></select></form>
回去自己改改就OK了
解决方案三:
引用1楼c48111926的回复:
HTMLcode<script><!--<%'二级数据保存到数组Dimcount2,cityRS,citySQLsetcityRS=server.createobject("adodb.recordset")citySQL="select*fromsys_city"cityRS.opencitySQL,conn,1,1%>varsubval2=new……
楼上的篡位了,这可是jsp的地盘,容不得asp瞎胡闹
解决方案四:
LZ你题意不清你没有说是在JSP还是EXT还是asp中实现。
解决方案五:
联动其实也没什么首先你定义三个方法分给三个select然后再方法中用AJAX或DWR进行在后台取数据然后动态填充数据