日期:2014-05-16  浏览次数:20474 次

js 解析xml文件实现省市级联下拉菜单

? js 解析xml文件实现省市级联下拉菜单

?

写一个省市的XML文档

? city.xml

?? <!--EndFragment-->

<?xml version="1.0" encoding="UTF-8"?>
<cities>
    <province  name="北京">
        <city>大兴</city>
        <city>海淀</city>
        <city>沙河</city>
        <city>朝阳</city>
        <city>昌平</city>
        <city>西单</city>
        <city>中关村</city>    
    </province>
        <province  name="河北">
        <city>石家庄</city>
        <city>保定</city>
        <city>承德</city>
        <city>邢台</city>
        <city>邯郸</city>
        <city>廊坊</city>
        <city>唐山</city>    
    </province>
        <province  name="陕西">
        <city>西安</city>
        <city>咸阳</city>
        <city>铜川</city>
        <city>渭南</city>
        <city>汉中</city>
        <city>商洛</city>
        <city>延安</city>
    
    </province>


</cities>

???

?

?

?

???? city.html

??

?

???

?????

  <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN" Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>city.html</title>
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="this is my page">
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
	</head>

	<body>

		<h1>
			解析xml文件实现省市级联下拉单
		</h1>

		<div>
			<span> <select id="province" name="province">
					<option>
						请选择省
					</option>
				</select> </span>
			<span> <select id="cities" name="city">
					<option>请选择相应省下面的市
					</option>
				</select> </span>
				<span> <select id="counties" name="county">
					<option>请选择相应市下面的县
					</option>
				</select> </span>
		</div>
	</body>
</html>

???

?

?

??? javascript

??