日期:2014-05-17 浏览次数:20468 次
var cityList = new Array( ); cityList['北京'] = ['朝阳区','东城区','西城区', '海淀区','宣武区','丰台区','怀柔','延庆','房山']; cityList['上海'] = ['宝山区','长宁区','丰贤区', '虹口区','黄浦区','青浦区','南汇区','徐汇区','卢湾区']; cityList['广州'] = ['天河区','海珠区','南沙区', '白云区','嘉湾区','越秀区','黄埔区','罗岗区','番寓区','花都区']; cityList['深圳'] = ['福田区', '罗湖区', '盐田区', '宝安区', '龙岗区', '南山区', '深圳周边']; cityList['重庆'] =['俞中区', '南岸区', '江北区', '沙坪坝区', '九龙坡区', '渝北区', '大渡口区', '北碚区', '巴南区', '万盛区', '涪凌', '江津']; cityList['天津'] = ['和平区', '河西区', '南开区', '河北区', '河东区', '红桥区', '塘古区', '开发区', '西青区', '津南区','东丽区']; function changeCity( ) { var province=document.getElementById("province").value; document.getElementById("city").options.length=0; for (var i in cityList) { if (i == province) { for (var j in cityList[i]) { document.getElementById("city").options.add(new Option(cityList[i][j], cityList[i][j])); } } } document.getElementById("city").options.selctIndex=0; } function loadAll( ) { for (var i in cityList) { document.getElementById("province").options.add(new Option(i, i)); } document.getElementById("province").selectedIndex = 0; }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>无标题页</title> <script src="JS/citys.js" type="text/javascript"></script> </head> <body> <form id="myform" runat="server"> <select id="province" runat="server" onchange="changeCity()"> <option>----省份----</option> </select> <select id="city" runat="server"> <option>----城市----</option> </select> <script type="text/javascript">loadAll()</script> </form> </body> </html>
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="无标题页" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> <script src="JS/citys.js" type="text/javascript"></script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <select id="province" runat="server" onchange="changeCity()"> <option>----省份----</option> </select> <select id="city" runat="server"> <option>----城市----</option>