|
Provinces.xml
復制代碼 代碼如下:
<?xml version="1.0"?>
<Root>
<Province ID="1" Name="安徽">
<City ID="1">安慶市</City>
<City ID="2">蚌埠市</City>
<City ID="3">亳州市</City>
<City ID="4">巢湖市</City>
<City ID="5">池州市</City>
<City ID="6">滁州市</City>
<City ID="7">阜陽市</City>
<City ID="8">合肥市</City>
<City ID="9">淮北市</City>
<City ID="10">淮南市</City>
<City ID="11">黃山市</City>
<City ID="12">六安市</City>
<City ID="13">馬鞍山市</City>
<City ID="14">宿州市</City>
<City ID="15">銅陵市</City>
<City ID="16">蕪湖市</City>
<City ID="17">宣城市</City>
</Province>
<Province ID="2" Name="北京">
<City ID="18">昌平區</City>
<City ID="19">朝陽區</City>
<City ID="20">崇文區</City>
<City ID="21">大興區</City>
<City ID="22">東城區</City>
<City ID="23">房山區</City>
<City ID="24">豐臺區</City>
<City ID="25">海淀區</City>
<City ID="26">懷柔區</City>
<City ID="27">門頭溝區</City>
<City ID="28">密云縣</City>
<City ID="29">平谷區</City>
<City ID="30">石景山區</City>
<City ID="31">順義區</City>
<City ID="32">通州區</City>
<City ID="33">西城區</City>
<City ID="34">宣武區</City>
<City ID="35">延慶縣</City>
</Province>
<Province ID="3" Name="重慶">
<City ID="36">巴南區</City>
<City ID="37">北碚區</City>
<City ID="38">長壽區</City>
<City ID="39">達州市</City>
<City ID="40">涪陵區</City>
<City ID="41">江北區</City>
<City ID="42">九龍坡區</City>
<City ID="43">南岸區</City>
<City ID="44">黔江區</City>
<City ID="45">沙坪壩區</City>
<City ID="46">雙橋區</City>
<City ID="47">萬盛區</City>
<City ID="48">萬州區</City>
<City ID="49">渝北區</City>
<City ID="50">渝中區</City>
<City ID="51">璧山縣</City>
<City ID="52">城口縣</City>
<City ID="53">大足縣</City>
<City ID="54">墊江縣</City>
<City ID="55">豐都縣</City>
<City ID="56">奉節縣</City>
<City ID="57">合川市</City>
<City ID="58">江津市</City>
<City ID="59">開縣</City>
<City ID="60">梁平縣</City>
<City ID="61">南川市</City>
<City ID="62">彭水苗族土家族自治縣</City>
<City ID="63">綦江縣</City>
<City ID="64">榮昌縣</City>
<City ID="65">石柱土家族自治縣</City>
<City ID="66">銅梁縣</City>
<City ID="67">潼南縣</City>
<City ID="68">巫山縣</City>
<City ID="69">巫溪縣</City>
<City ID="70">武隆縣</City>
<City ID="71">秀山土家族苗族自治縣</City>
<City ID="72">永川市</City>
<City ID="73">酉陽土家族苗族自治縣</City>
<City ID="74">云陽縣</City>
<City ID="75">忠縣</City>
</Province>
<Province ID="4" Name="福建">
<City ID="76">城廂區</City>
<City ID="77">福州市</City>
<City ID="78">涵江區</City>
<City ID="79">荔城區</City>
<City ID="80">龍巖市</City>
<City ID="81">南平市</City>
<City ID="82">寧德市</City>
<City ID="83">莆田市</City>
<City ID="84">泉州市</City>
<City ID="85">三明市</City>
<City ID="86">廈門市</City>
<City ID="87">秀嶼區</City>
<City ID="88">秀嶼區</City>
<City ID="89">漳州市</City>
</Province>
<Province ID="5" Name="甘肅">
<City ID="90">白銀市</City>
<City ID="91">定西市</City>
<City ID="92">甘南州</City>
<City ID="93">海南州</City>
<City ID="94">金昌市</City>
<City ID="95">酒泉市</City>
<City ID="96">蘭州市</City>
<City ID="97">臨夏州</City>
<City ID="98">隴南市</City>
<City ID="99">平涼市</City>
<City ID="100">慶陽市</City>
<City ID="101">天水市</City>
<City ID="102">武威市</City>
<City ID="103">張掖市</City>
</Province>
<Province ID="6" Name="廣東">
<City ID="104">潮州市</City>
<City ID="105">東莞市</City>
<City ID="106">佛山市</City>
<City ID="107">廣州市</City>
<City ID="108">河源市</City>
<City ID="109">惠州市</City>
<City ID="110">江門市</City>
<City ID="111">揭陽市</City>
<City ID="112">茂名市</City>
<City ID="113">梅州市</City>
<City ID="114">清遠市</City>
<City ID="115">汕頭市</City>
<City ID="116">汕尾市</City>
<City ID="117">韶關市</City>
<City ID="118">深圳市</City>
<City ID="119">陽江市</City>
<City ID="120">云浮市</City>
<City ID="121">湛江市</City>
<City ID="122">肇慶市</City>
<City ID="123">中山市</City>
<City ID="124">珠海市</City>
</Province>
<Province ID="7" Name="廣西">
<City ID="125">百色市</City>
<City ID="126">北海市</City>
<City ID="127">崇左市</City>
<City ID="128">防城港市</City>
<City ID="129">貴港市</City>
<City ID="130">桂林市</City>
<City ID="131">河池市</City>
<City ID="132">賀州市</City>
<City ID="133">來賓市</City>
<City ID="134">柳州市</City>
<City ID="135">南寧市</City>
<City ID="136">欽州市</City>
<City ID="137">梧州市</City>
<City ID="138">玉林市</City>
</Province>
<Province ID="8" Name="貴州">
<City ID="139">安順市</City>
<City ID="140">畢節地區</City>
<City ID="141">貴陽市</City>
<City ID="142">六盤水市</City>
<City ID="143">黔東南苗族侗族自治州</City>
<City ID="144">黔南布依族苗族自治州</City>
<City ID="145">黔西南布依族苗族自治州</City>
<City ID="146">銅仁地區</City>
<City ID="147">遵義市</City>
</Province>
<Province ID="9" Name="海南">
<City ID="148">海口市</City>
<City ID="149">海南沿革</City>
<City ID="150">三亞市</City>
<City ID="151">大渡口區</City>
</Province>
<Province ID="10" Name="河北">
<City ID="152">保定市</City>
<City ID="153">滄州市</City>
<City ID="154">承德市</City>
<City ID="155">邯鄲市</City>
<City ID="156">衡水市</City>
<City ID="157">廊坊市</City>
<City ID="158">秦皇島市</City>
<City ID="159">石家莊市</City>
<City ID="160">唐山市</City>
<City ID="161">邢臺市</City>
<City ID="162">張家口市</City>
</Province>
<Province ID="11" Name="河南">
<City ID="163">安陽市</City>
<City ID="164">鶴壁市</City>
<City ID="165">焦作市</City>
<City ID="166">開封市</City>
<City ID="167">洛陽市</City>
<City ID="168">漯河市</City>
<City ID="169">南陽市</City>
<City ID="170">平頂山市</City>
<City ID="171">濮陽市</City>
<City ID="172">三門峽市</City>
<City ID="173">商丘市</City>
<City ID="174">新鄉市</City>
<City ID="175">信陽市</City>
<City ID="176">許昌市</City>
<City ID="177">鄭州市</City>
<City ID="178">周口市</City>
<City ID="179">駐馬店市</City>
</Province>
<Province ID="12" Name="黑龍江">
<City ID="180">大慶市</City>
<City ID="181">大興安嶺地區</City>
<City ID="182">哈爾濱市</City>
<City ID="183">鶴崗市</City>
<City ID="184">黑河市</City>
<City ID="185">雞西市</City>
<City ID="186">佳木斯市</City>
<City ID="187">牡丹江市</City>
<City ID="188">七臺河市</City>
<City ID="189">齊齊哈爾市</City>
<City ID="190">雙鴨山市</City>
<City ID="191">綏化市</City>
<City ID="192">伊春市</City>
</Province>
<Province ID="13" Name="湖北">
<City ID="193">鄂州市</City>
<City ID="194">恩施土家族苗族自治州</City>
<City ID="195">黃岡市</City>
<City ID="196">黃石市</City>
<City ID="197">荊門市</City>
<City ID="198">荊州市</City>
<City ID="199">十堰市</City>
<City ID="200">隨州市</City>
<City ID="201">武漢市</City>
<City ID="202">咸寧市</City>
<City ID="203">襄樊市</City>
<City ID="204">孝感市</City>
<City ID="205">宜昌市</City>
</Province>
<Province ID="14" Name="湖南">
<City ID="206">長沙市</City>
<City ID="207">常德市</City>
<City ID="208">郴州市</City>
<City ID="209">衡陽市</City>
<City ID="210">懷化市</City>
<City ID="211">婁底市</City>
<City ID="212">邵陽市</City>
<City ID="213">湘潭市</City>
<City ID="214">湘西土家族苗族自治州</City>
<City ID="215">益陽市</City>
<City ID="216">永州市</City>
<City ID="217">岳陽市</City>
<City ID="218">張家界市</City>
<City ID="219">株洲市</City>
</Province>
<Province ID="15" Name="吉林">
<City ID="220">白城市</City>
<City ID="221">白山市</City>
<City ID="222">長春市</City>
<City ID="223">吉林市</City>
<City ID="224">遼源市</City>
<City ID="225">四平市</City>
<City ID="226">松原市</City>
<City ID="227">通化市</City>
<City ID="228">延邊朝鮮族自治州</City>
</Province>
<Province ID="16" Name="江蘇">
<City ID="229">常州市</City>
<City ID="230">淮安市</City>
<City ID="231">連云港市</City>
<City ID="232">南京市</City>
<City ID="233">南通市</City>
<City ID="234">蘇州市</City>
<City ID="235">宿遷市</City>
<City ID="236">泰州市</City>
<City ID="237">無錫市</City>
<City ID="238">徐州市</City>
<City ID="239">鹽城市</City>
<City ID="240">揚州市</City>
<City ID="241">鎮江市</City>
</Province>
<Province ID="17" Name="江西">
<City ID="242">撫州市</City>
<City ID="243">贛州市</City>
<City ID="244">吉安市</City>
<City ID="245">景德鎮市</City>
<City ID="246">九江市</City>
<City ID="247">南昌市</City>
<City ID="248">萍鄉市</City>
<City ID="249">上饒市</City>
<City ID="250">新余市</City>
<City ID="251">宜春市</City>
<City ID="252">鷹潭市</City>
</Province>
<Province ID="18" Name="遼寧">
<City ID="253">鞍山市</City>
<City ID="254">本溪市</City>
<City ID="255">朝陽市</City>
<City ID="256">大連市</City>
<City ID="257">丹東市</City>
<City ID="258">撫順市</City>
<City ID="259">阜新市</City>
<City ID="260">葫蘆島市</City>
<City ID="261">錦州市</City>
<City ID="262">遼陽市</City>
<City ID="263">盤錦市</City>
<City ID="264">沈陽市</City>
<City ID="265">鐵嶺市</City>
<City ID="266">營口市</City>
</Province>
<Province ID="19" Name="內蒙">
<City ID="267">阿拉善盟</City>
<City ID="268">巴彥淖爾市</City>
<City ID="269">包頭市</City>
<City ID="270">赤峰市</City>
<City ID="271">鄂爾多斯市</City>
<City ID="272">呼和浩特市</City>
<City ID="273">呼倫貝爾市</City>
<City ID="274">通遼市</City>
<City ID="275">烏海市</City>
<City ID="276">烏蘭察布市</City>
<City ID="277">錫林郭勒盟</City>
<City ID="278">興安盟</City>
</Province>
<Province ID="20" Name="寧夏">
<City ID="279">固原市</City>
<City ID="280">石嘴山市</City>
<City ID="281">吳忠市</City>
<City ID="282">博爾塔拉州</City>
<City ID="283">中衛市</City>
<City ID="440">銀川市</City>
</Province>
<Province ID="21" Name="青海">
<City ID="284">果洛州</City>
<City ID="285">海北州</City>
<City ID="286">海東地區</City>
<City ID="287">銀川市</City>
<City ID="288">海西州</City>
<City ID="289">黃南州</City>
<City ID="290">西寧市</City>
<City ID="291">玉樹州</City>
</Province>
<Province ID="22" Name="山東">
<City ID="292">濱州市</City>
<City ID="293">德州市</City>
<City ID="294">東營市</City>
<City ID="295">菏澤市</City>
<City ID="296">濟南市</City>
<City ID="297">濟寧市</City>
<City ID="298">萊蕪市</City>
<City ID="299">聊城市</City>
<City ID="300">臨沂市</City>
<City ID="301">青島市</City>
<City ID="302">日照市</City>
<City ID="303">泰安市</City>
<City ID="304">威海市</City>
<City ID="305">濰坊市</City>
<City ID="306">煙臺市</City>
<City ID="307">棗莊市</City>
<City ID="308">淄博市</City>
</Province>
<Province ID="23" Name="山西">
<City ID="309">長治市</City>
<City ID="310">大寧縣</City>
<City ID="311">大同市</City>
<City ID="312">晉城市</City>
<City ID="313">晉中市</City>
<City ID="314">臨汾市</City>
<City ID="315">呂梁市</City>
<City ID="316">朔州市</City>
<City ID="317">太原市</City>
<City ID="318">忻州市</City>
<City ID="319">陽泉市</City>
<City ID="320">運城市</City>
</Province>
<Province ID="24" Name="陜西">
<City ID="321">安康市</City>
<City ID="322">寶雞市</City>
<City ID="323">漢中市</City>
<City ID="324">嘉峪關市</City>
<City ID="325">銅川市</City>
<City ID="326">渭南市</City>
<City ID="327">西安市</City>
<City ID="328">咸陽市</City>
<City ID="329">延安市</City>
<City ID="330">榆林市</City>
</Province>
<Province ID="25" Name="上海">
<City ID="331">寶山區</City>
<City ID="332">長寧區</City>
<City ID="333">崇明縣</City>
<City ID="334">奉賢區</City>
<City ID="335">虹口區</City>
<City ID="336">黃浦區</City>
<City ID="337">嘉定區</City>
<City ID="338">金山區</City>
<City ID="339">靜安區</City>
<City ID="340">盧灣區</City>
<City ID="341">閔行區</City>
<City ID="342">南匯區</City>
<City ID="343">浦東新區</City>
<City ID="344">普陀區</City>
<City ID="345">青浦區</City>
<City ID="346">松江區</City>
<City ID="347">徐匯區</City>
<City ID="348">楊浦區</City>
<City ID="349">閘北區</City>
</Province>
<Province ID="26" Name="四川">
<City ID="350">阿壩藏族羌族自治州</City>
<City ID="351">巴中市</City>
<City ID="352">成都市</City>
<City ID="353">六盤水市</City>
<City ID="354">德陽市</City>
<City ID="355">甘孜藏族自治州</City>
<City ID="356">廣安市</City>
<City ID="357">廣元市</City>
<City ID="358">樂山市</City>
<City ID="359">涼山彝族自治州</City>
<City ID="360">瀘州市</City>
<City ID="361">眉山市</City>
<City ID="362">綿陽市</City>
<City ID="363">內江市</City>
<City ID="364">南充市</City>
<City ID="365">攀枝花市</City>
<City ID="366">遂寧市</City>
<City ID="367">雅安市</City>
<City ID="368">宜賓市</City>
<City ID="369">資陽市</City>
<City ID="370">自貢市</City>
</Province>
<Province ID="27" Name="天津">
<City ID="371">和平區</City>
<City ID="372">河東區</City>
<City ID="373">河西區</City>
<City ID="374">南開區</City>
<City ID="375">河北區</City>
<City ID="376">紅橋區</City>
<City ID="377">塘沽區</City>
<City ID="378">漢沽區</City>
<City ID="379">大港區</City>
<City ID="380">東麗區</City>
<City ID="381">西青區</City>
<City ID="382">津南區</City>
<City ID="383">北辰區</City>
<City ID="384">武清區</City>
<City ID="385">寶坻區</City>
<City ID="386">寧河縣</City>
<City ID="387">靜海縣</City>
<City ID="388">薊縣</City>
</Province>
<Province ID="28" Name="西藏">
<City ID="389">阿里地區</City>
<City ID="390">昌都地區</City>
<City ID="391">拉薩市</City>
<City ID="392">商洛市</City>
<City ID="393">那曲地區</City>
<City ID="394">日喀則地區</City>
<City ID="395">山南地區</City>
</Province>
<Province ID="29" Name="新疆">
<City ID="396">阿克蘇地區</City>
<City ID="397">阿勒泰地區</City>
<City ID="398">巴音郭楞州</City>
<City ID="399">觀塘區</City>
<City ID="400">昌吉州</City>
<City ID="401">哈密地區</City>
<City ID="402">和田地區</City>
<City ID="403">喀什地區</City>
<City ID="404">克拉瑪依市</City>
<City ID="405">克孜勒蘇州</City>
<City ID="406">塔城地區</City>
<City ID="407">吐魯番地區</City>
<City ID="408">烏魯木齊市</City>
<City ID="409">伊犁州</City>
</Province>
<Province ID="30" Name="云南">
<City ID="410">保山市</City>
<City ID="411">楚雄彝族自治州</City>
<City ID="412">大理白族自治州</City>
<City ID="413">德宏傣族景頗族自治州</City>
<City ID="414">迪慶藏族自治州</City>
<City ID="415">紅河哈尼族彝族自治州</City>
<City ID="416">昆明市</City>
<City ID="417">麗江市</City>
<City ID="418">臨滄市</City>
<City ID="419">怒江傈傈族自治州</City>
<City ID="420">曲靖市</City>
<City ID="421">思茅市</City>
<City ID="422">文山壯族苗族自治州</City>
<City ID="423">西雙版納傣族自治州</City>
<City ID="424">玉溪市</City>
<City ID="425">昭通市</City>
</Province>
<Province ID="31" Name="浙江">
<City ID="426">杭州市</City>
<City ID="427">湖州市</City>
<City ID="428">嘉興市</City>
<City ID="429">金華市</City>
<City ID="430">麗水市</City>
<City ID="431">寧波市</City>
<City ID="432">衢州市</City>
<City ID="433">紹興市</City>
<City ID="434">臺州市</City>
<City ID="435">溫州市</City>
<City ID="436">舟山市</City>
</Province>
<Province ID="32" Name="臺灣">
<City ID="437">臺灣</City>
</Province>
<Province ID="33" Name="香港">
<City ID="438">香港</City>
</Province>
<Province ID="34" Name="澳門">
<City ID="439">澳門</City>
</Province>
</Root>
Common.js
復制代碼 代碼如下:
//省份,城市
var provinceDom = null;
function InItDom(fname) {
var tempdom;
try {
tempdom = new ActiveXObject("Microsoft.XMLDOM");
} catch (e) {
try {
tempdom = document.implementation.createDocument("", "", null);
}
catch (e) {
alert(e.message);
}
}
try {
tempdom.async = false;
tempdom.load(fname);
//alert(tempdom.childNodes.length);
}
catch (e) {
}
return tempdom;
}
function InitProvince(provinceid) {
var province = document.getElementById(provinceid);
province.length = 0;
if (provinceDom == null)
provinceDom = InItDom("../config/Provinces.xml");
if (provinceDom != null) {
var proNodes = provinceDom.childNodes[1].childNodes;
//alert(proNodes.length);
for (var i = 0; i < proNodes.length; i++) {
var tempOption = document.createElement("option");
tempOption.value = proNodes[i].getAttribute("Name");
tempOption.text = proNodes[i].getAttribute("Name");
province.options.add(tempOption);
}
//alert(proNodes[1].getAttribute("Name"));
}
}
function ResetCity(province, cityname) {
var pname=province.value;
var city = document.getElementById(cityname);
city.length = 0;
if (provinceDom == null)
provinceDom = InItDom("../config/Provinces.xml");
if (provinceDom != null) {
// alert(provinceDom.childNodes[1].childNodes.length);
var root = provinceDom.selectNodes("Root")[0];
//Nodes = objXMLDoc.selectNodes("test/test1/test1");
// alert(root.childNodes.length);
for (var i = 0; i < root.childNodes.length; i++) {
if (root.childNodes[i].getAttribute("Name") == pname) {
for (var j = 0; j < root.childNodes[i].childNodes.length; j++) {
var tempOption = document.createElement("option");
tempOption.value = root.childNodes[i].childNodes[j].text;
tempOption.text = root.childNodes[i].childNodes[j].text;
city.options.add(tempOption);
}
break;
}
}
}
}
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');</script>
ASPx.cs:
復制代碼 代碼如下:
string province=Request["ddlUProvince"];
string city=Request["ddlUCity"];
JavaScript技術:JS+XML 省份和城市之間的聯動實現代碼,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。