JS+XML 实现 省份和城市之间的联动
用JS来操作一个XML文档来实现一个简单的表单联动
这里是:xml文件
这里是:JS文件
aspx页面:
<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td height="25" width="30%" align="right">
UName :
</td>
<td height="25" width="*" align="left">
<asp:TextBox ID="txtUName" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td height="25" width="30%" align="right">
UCountry :
</td>
<td height="25" width="*" align="left">
<asp:TextBox ID="txtUCountry" runat="server" Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<td height="25" width="30%" align="right">
UProvince :
</td>
<td height="25" width="*" align="left">
<asp:DropDownList ID="ddlUProvince" runat="server" onchange="ResetCity(this,'ddlUCity');">
</asp:DropDownList>
</td>
</tr>
<tr>
<td height="25" width="30%" align="right">
UCity :
</td>
<td height="25" width="*" align="left">
<asp:DropDownList ID="ddlUCity" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td height="25" colspan="2">
<div align="center">
<asp:Button ID="btnAdd" runat="server" Text="注册" OnClick="btnAdd_Click"></asp:Button>
</div>
</td>
</tr>
</table>
<script>
InitProvince('ddlUProvince');
ResetCity(document.getElementById("ddlUProvince"), "ddlUCity");
</script>
aspx.cs:
string province=Request["ddlUProvince"];
string city=Request["ddlUCity"];