<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script language="javascript">
var xmlHttp;
function createXMLHttp() {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function getCity() {
createXMLHttp();
xmlHttp.open("POST", "allarea.xml");
xmlHttp.onreadystatechange = getCityback;
xmlHttp.send(null);
}
function getCityback() {
if (xmlHttp.readyState == 4) {
alert(xmlHttp.status)
if (xmlHttp.status == 200) {
var allarea = xmlHttp.responseXML
.getElementsByTagName("allarea")[0].childNodes;
alert(allarea[0]);
var select = document.getElementById("city");
for ( var i = 0; i < allarea.length; i++) {
var area = allarea[i];
var option = document.createElement("option");
var id = area.getElementsByTagName("id")[0];
var title = area.getElementsByTagName("title")[0].firstChid.nodeValue;
option.setAttribute("value", id);
option.apppendChild(document.createTextNode(title));
select.appendChild(option);
}
}
}
}
</script>
</HEAD>
<BODY οnlοad="getCity()">
<form action="" method="post">
请选择喜欢的城市:
<select name="city">
<option value="0">
-请选择城市-
</option>
</select>
</form>
</BODY>
</HTML>
<?xml version="1.0" encoding="GBK"?>
<allarea id="1">
<area id="0">
<id>1</id>
<title>beijing</title>
</area>
<area>
<id>2</id>
<title>tianjing</title>
</area>
</allarea>