按照视频里面的代码做却出不来结果,求指点:[code=jscript]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>城市选择</title>
</head>
<body>
<select id="province">
<option>请选择....</option>
<option>福建</option>
<option>浙江</option>
<option>广东</option>
</select>
<select id="city">
<option>请选择....</option>
</select>
</body>
<script type="text/javascript" charset="utf-8">
window.onload=function(){
document.getElementById("province").onchange=function(){
var xmlDoc=parseXML("select.xml");
var provinceElements=xmlDoc.getElementsByTagName("province");
alert(provinceElements.length);
}
}
function parseXML(filename) {
try//Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
} catch(e) {
try//Firefox, Mozilla, Opera, etc.
{
xmlDoc = document.implementation.createDocument("", "", null);
} catch(e) {
}
}
xmlDoc.async=false;
xmlDoc.load(filename);
return xmlDoc;
}
</script>
</html>[/code][code=xml]<?xml version="1.0" encoding="GB2312"?>
<china>
<province name="福建">
<city>福州</city>
<city>泉州</city>
<city>厦门</city>
<city>宁德</city>
<city>武夷山</city>
</province>
<province name="浙江">
<city>杭州</city>
<city>宁波</city>
<city>绍兴</city>
<city>钱塘</city>
</province>
<province name="广东">
<city>广州</city>
<city>佛山</city>
<city>珠海</city>
</province>
</china>[/code]我想测试XML是否解析成功可是这样写每次都弹出0,不知道哪里错了? |