您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)從xml中獲取城市,省份名稱(chēng)的方法的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。
//******************************************************************************** //* * // 功能描述:從xml中獲取數(shù)據(jù) // 版本編號(hào):owendu V1.1 // 初始創(chuàng)建: 2006.08.27 // 最后修改: 2006.10.08 //* * //******************************************************************************** //根據(jù)cityid,獲取返回cityname ---------------xmlurl 指的是整個(gè)站點(diǎn)的路征 //頁(yè)面調(diào)用方式如下:<script language=javascript>GetCityName("<%=cityid%>","<%=System.Configuration.ConfigurationSettings.AppSettings["LocalSiteURL"]%>")</script> function GetCityName(cityid,xmlurl) { var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0"); XmlDoc_city.async=false; XmlDoc_city.validateOnParse=false; var Url=xmlurl+"XmlData/city.xml"; XmlDoc_city.load(Url); // if (XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "") { var city; var cities = XmlDoc_city.documentElement.selectNodes("city"); for (var i=0; i < cities.length; i++) { city = cities[i]; if (city.getAttribute("cityid") == cityid) { document.write(city.getAttribute("cityname")); break; } //obj2.options[obj2.length] = new Option(city.getAttribute("cityname"),city.getAttribute("cityid")); } } // else // { //alert('您的瀏覽器不支持xml文件讀取,于是本頁(yè)面禁止您的操作,推薦使用IE5.0以上可以解決此問(wèn)題!'); // } } //根據(jù)省份id,獲取返回省名 ---------------xmlurl 指的是整個(gè)站點(diǎn)的路征 function GetPRoviceName(pid,xmlurl) { var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0"); XmlDoc_city.async=false; XmlDoc_city.validateOnParse=false; var Url=xmlurl+"XmlData/province.xml"; XmlDoc_city.load(Url); if(XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "") { var city; var cities = XmlDoc_city.documentElement.selectNodes("province"); for (var i=0; i < cities.length; i++) { city = cities[i]; if (city.getAttribute("provinceid") == pid) { document.write(city.getAttribute("provincename")); break; } } } } //根據(jù)地區(qū)districtid,獲取返回地區(qū)名 ---------------xmlurl 指的是整個(gè)站點(diǎn)的路征 function GetProviceName(districtid,xmlurl) { var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0"); XmlDoc_city.async=false; XmlDoc_city.validateOnParse=false; var Url=xmlurl+"XmlData/district.xml"; XmlDoc_city.load(Url); if(XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "") { var city; var cities = XmlDoc_city.documentElement.selectNodes("district"); for (var i=0; i < cities.length; i++) { city = cities[i]; if (city.getAttribute("districtid") == pid) { document.write(city.getAttribute("districtname")); break; } } } } //根據(jù)省份id,城市id,地區(qū)(縣)id,獲取返回省城市名地區(qū)名 ---------------xmlurl 指的是整個(gè)站點(diǎn)的路征 function GetName(pid,cityid,districtid ,xmlurl) { var cityname=""; var provicename=""; var districtname=""; // var XmlDoc_p = new ActiveXObject("MSXML2.DOMDocument.3.0"); XmlDoc_p.async=false; XmlDoc_p.validateOnParse=false; var UrlProvice=xmlurl+"XmlData/province.xml"; XmlDoc_p.load(UrlProvice); // var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0"); XmlDoc_city.async=false; XmlDoc_city.validateOnParse=false; var Urlcity=xmlurl+"XmlData/city.xml"; XmlDoc_city.load(Urlcity); // var XmlDoc_district = new ActiveXObject("MSXML2.DOMDocument.3.0"); XmlDoc_district.async=false; XmlDoc_district.validateOnParse=false; var Urldis=xmlurl+"XmlData/district.xml"; XmlDoc_district.load(Urldis); // if(XmlDoc_p.readyState == 4 && XmlDoc_p.xml != "") { var provice; var provices = XmlDoc_city.documentElement.selectNodes("province"); for (var i=0; i < provices.length; i++) { provice = provices[i]; if (provice.getAttribute("provinceid") == pid) { provicename=provice.getAttribute("provincename"); break; } } } if(XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "") { var city; var citys = XmlDoc_city.documentElement.selectNodes("city"); for (var i=0; i < citys.length; i++) { city = citys[i]; if (city.getAttribute("cityid") == cityid) { cityname=city.getAttribute("cityname"); break; } } } if(XmlDoc_district.readyState == 4 && XmlDoc_district.xml != "") { var district; var districts = XmlDoc_district.documentElement.selectNodes("district"); for (var i=0; i < districts.length; i++) { district = districts[i]; if (district.getAttribute("districtid") == districtid) { districtname=district.getAttribute("districtname"); break; } } } var name=provicename+" "+cityname+" "+ districtname; document.write(name); }
感謝各位的閱讀!關(guān)于從xml中獲取城市,省份名稱(chēng)的方法就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。