- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安XML教程基地 来源:黑客防线网安XML教程基地 浏览次数:0 |
最近没事,写了个在项目经常要取城市或省份名的方法,所以改成了一个类.方便以后调用
//********************************************************************************
//* *
// 功能描述:从xml中获取数据
// 版本编号:owendu V1.1
// 初始创建: 2006.08.27
// 最后修改: 2006.10.08
//* *
//********************************************************************************
//根据cityid,获取返回cityname ---------------xmlurl 指的是整个站点的路征
//页面调用方式如下:<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文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!');
// }
}
//根据省份id,获取返回省名 ---------------xmlurl 指的是整个站点的路征
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;
}
}
}
}
//根据地区districtid,获取返回地区名 ---------------xmlurl 指的是整个站点的路征
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;
}
}
}
}
//根据省份id,城市id,地区(县)id,获取返回省城市名地区名 ---------------xmlurl 指的是整个站点的路征
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);
}
http://www.cnblogs.com/owendu/archive/2006/10/16/530580.html
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |