【IT168技术文档】
最近忙没时间详细解释,先把通用的源码贴出自己看。
出于对性能的考虑,把省市两级写成JS数组,把县区(镇)两级写在 Oracle 里。通过 JS 触发 C# 去读取数据库,然后将数据回传给 JS ,再绑定显示。
操作 <select> 采用更通用的 createElement() 而没有使用 options.add()
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Area.aspx.cs" Inherits="Area" %> <!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 runat="server"> <title>地区</title> </head> <body> <form id="form1" runat="server"> <table> <tr> <td> <select id="SF"> <option selected="selected">—请选择—</option> </select> </td> <td> <select id="CS"> <option selected="selected">—请选择—</option> </select> </td> <td> <select id="Xian"> <option selected="selected">—请选择—</option> </select> </td> <td> <select id="Zhen"> <option selected="selected">—请选择—</option> </select> </td> </tr> </table> <script type="text/javascript"> var aDQ=new Array(); aDQ[0]=["11","北京","0","bj"]; aDQ[1]=["12","天津","0","tj"]; aDQ[2]=["13","河北","0","hb"]; aDQ[3]=["14","山西","0","shang"]; aDQ[4]=["15","内蒙古","0","nmg"]; aDQ[5]=["21","辽宁","0","ln"]; aDQ[6]=["22","吉林","0","jl"]; aDQ[7]=["23","黑龙江","0","hlj"]; aDQ[8]=["31","上海","0","sh"]; aDQ[9]=["32","江苏","0","js"]; aDQ[10]=["33","浙江","0","zhej"]; aDQ[11]=["34","安徽","0","ah"]; aDQ[12]=["35","福建","0","fj"]; aDQ[13]=["36","江西","0","jw"]; aDQ[14]=["37","山东","0","sd"]; aDQ[15]=["41","河南","0","he"]; aDQ[16]=["42","湖北","0","hu"]; aDQ[17]=["43","湖南","0","hn"]; aDQ[18]=["44","广东","0","gd"]; aDQ[19]=["45","广西","0","gx"]; aDQ[20]=["46","海南","0","hain"]; aDQ[21]=["50","重庆","0","cq"]; aDQ[22]=["51","四川","0","sc"]; aDQ[23]=["52","贵州","0","gui"]; aDQ[24]=["53","云南","0","yn"]; aDQ[25]=["54","西藏","0","wc"]; aDQ[26]=["61","陕西","0","shangx"]; aDQ[27]=["62","甘肃","0","gs"]; aDQ[28]=["63","青海","0","qh"]; aDQ[29]=["64","宁夏","0","nx"]; aDQ[30]=["65","新疆","0","xj"]; aDQ[31]=["71","台湾","0","tw"]; aDQ[32]=["81","香港","0","xg"]; aDQ[33]=["82","澳门","0","am"]; aDQ[34]=["1101","北京城区","11","bjcq"]; aDQ[35]=["1102","北京县区","11","bjxq"]; aDQ[36]=["1201","天津城区","12","tjcq"]; aDQ[37]=["1202","天津县区","12","tjxq"]; aDQ[38]=["1301","石家庄","13","sjz"]; aDQ[39]=["1302","唐山","13","hbts"]; aDQ[40]=["1303","秦皇岛","13","qhd"]; aDQ[41]=["1304","邯郸","13","hd"]; aDQ[42]=["1305","邢台","13","hbxt"]; aDQ[43]=["1306","保定","13","bd"]; aDQ[44]=["1307","张家口","13","zjk"]; aDQ[45]=["1308","承德","13","cd"]; aDQ[46]=["1309","沧州","13","hbcz"]; aDQ[47]=["1310","廊坊","13","lf"]; aDQ[48]=["1311","衡水","13","hbhs"]; aDQ[49]=["1401","太原","14","ty"]; aDQ[50]=["1402","大同","14","dt"]; aDQ[51]=["1403","阳泉","14","yq"]; aDQ[52]=["1404","长治","14","swcz"]; aDQ[53]=["1405","晋城","14","swjc"]; aDQ[54]=["1406","朔州","14","swsz"]; aDQ[55]=["1501","呼和浩特","15","hhht"]; aDQ[56]=["1502","包头","15","bt"]; aDQ[57]=["1503","乌海","15","nmgwh"]; aDQ[58]=["1504","赤峰","15","cf"]; aDQ[59]=["1521","呼伦贝尔盟","15","hlbem"]; aDQ[60]=["1522","兴安盟","15","xam"]; aDQ[61]=["1523","哲里木盟","15","zlmm"]; aDQ[62]=["1525","锡林郭勒盟","15","wlglm"]; aDQ[63]=["1526","乌兰察布盟","15","wlcbm"]; aDQ[64]=["1527","鄂尔多斯","15","eeds"]; aDQ[65]=["1528","巴彦淖尔盟","15","bynem"]; aDQ[66]=["1529","阿拉善盟","15","alsm"]; aDQ[67]=["2101","沈阳","21","lnsy"]; aDQ[68]=["2102","大连","21","dl"]; aDQ[69]=["2103","鞍山","21","as"]; aDQ[70]=["2104","抚顺","21","lnfs"]; aDQ[71]=["2105","本溪","21","bx"]; aDQ[72]=["2106","丹东","21","dd"]; aDQ[73]=["2107","锦州","21","jz"]; aDQ[74]=["2108","营口","21","yk"]; aDQ[75]=["2109","阜新","21","fx"]; aDQ[76]=["2110","辽阳","21","lnly"]; aDQ[77]=["2111","盘锦","21","pj"]; aDQ[78]=["2112","铁岭","21","lntl"]; aDQ[79]=["2113","朝阳","21","cy"]; aDQ[80]=["2114","葫芦岛","21","hld"]; aDQ[81]=["2201","长春","22","cc"]; aDQ[82]=["2202","吉林","22","jljl"]; aDQ[83]=["2203","四平","22","sp"]; aDQ[84]=["2204","辽源","22","jlly"]; aDQ[85]=["2205","通化","22","th"]; aDQ[86]=["2206","白山","22","bs"]; aDQ[87]=["2207","松原","22","jlsy"]; aDQ[88]=["2208","白城","22","bc"]; aDQ[89]=["2224","延边","22","jlyb"]; aDQ[90]=["2301","哈尔滨","23","heb"]; aDQ[91]=["2302","齐齐哈尔","23","qqhe"]; aDQ[92]=["2303","鸡西","23","hljjw"]; aDQ[93]=["2304","鹤岗","23","hg"]; aDQ[94]=["2305","双鸭山","23","sys"]; aDQ[95]=["2306","大庆","23","dq"]; aDQ[96]=["2307","伊春","23","hljyc"]; aDQ[97]=["2308","佳木斯","23","jms"]; aDQ[98]=["2309","七台河","23","qth"]; aDQ[99]=["2310","牡丹江","23","mdj"]; aDQ[100]=["2311","黑河","23","hh"]; aDQ[101]=["3101","上海市区","31","shsq"]; aDQ[102]=["3102","上海县区","31","shxq"]; aDQ[103]=["3201","南京","32","nj"]; aDQ[104]=["3202","无锡","32","ww"]; aDQ[105]=["3203","徐州","32","xz"]; aDQ[106]=["3204","常州","32","jscz"]; aDQ[107]=["3205","苏州","32","shu"]; aDQ[108]=["3206","南通","32","nt"]; aDQ[109]=["3207","连云港","32","lyg"]; aDQ[110]=["3208","淮安","32","ha"]; aDQ[111]=["3209","盐城","32","jsyc"]; aDQ[112]=["3210","扬州","32","yz"]; aDQ[113]=["3211","镇江","32","jszj"]; aDQ[114]=["3212","泰州","32","tz"]; aDQ[115]=["3213","宿迁","32","sq"]; aDQ[116]=["3301","杭州","33","han"]; aDQ[117]=["3302","宁波","33","nb"]; aDQ[118]=["3303","温州","33","zjwz"]; aDQ[119]=["3304","嘉兴","33","jx"]; aDQ[120]=["3305","湖州","33","zjhz"]; aDQ[121]=["3306","绍兴","33","sx"]; aDQ[122]=["3307","金华","33","jh"]; aDQ[123]=["3308","衢州","33","zjqz"]; aDQ[124]=["3309","舟山","33","zjzs"]; aDQ[125]=["3310","台州","33","zjtz"]; aDQ[126]=["3311","义乌","33","yw"]; aDQ[127]=["3325","丽水","33","zjls"]; aDQ[128]=["3401","合肥","34","hf"]; aDQ[129]=["3402","芜湖","34","wh"]; aDQ[130]=["3403","蚌埠","34","bb"]; aDQ[131]=["3404","淮南","34","hnx"]; aDQ[132]=["3405","马鞍山","34","mas"];