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

Firefox提示"undefined",IE正常显示!
XML文件内容:
<?xml   version= "1.0 "   encoding= "gb2312 "   ?>
<sitemainmenu>
<item>
<enmenu> Home </enmenu>
<chmenu> 首页 </chmenu>
<url> / </url>
</item>
<item>
<enmenu> Product </enmenu>
<chmenu> 产品资讯 </chmenu>
<url> /product/ </url>
</item>
<item>
<enmenu> Support </enmenu>
<chmenu> 技术支持 </chmenu>
<url> /support/ </url>
</item>
<item>
<enmenu> Customer </enmenu>
<chmenu> 客户服务 </chmenu>
<url> /service/ </url>
</item>
<item>
<enmenu> Information </enmenu>
<chmenu> 信息中心 </chmenu>
<url> /company/ </url>
</item>
</sitemainmenu>

HTML内容:
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 无标题文档 </title>
</head>

<body>
<script   language= "javascript "   type= "text/javascript ">
<!--
var   xmlhttp;
try{
xmlhttp   =   new   ActiveXObject( 'Msxml2.XMLHTTP ');
}catch(e){
try{
xmlhttp=new   ActiveXObject( 'Microsoft.XMLHTTP ');
}catch(e){
try{
xmlhttp=new   XMLHttpRequest();
}catch(e){}
}
}

//创建对一个XML文件的请求
xmlhttp.open( "get ",   "sitemainmenu.xml ");
//表单值处理程序
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState   ==   4){
if(xmlhttp.status   ==200){
var   strdate=xmlhttp.responseXML;
readNewRecord(strdate);
}else{
alert(xmlhttp.status);
}
}
}
//发送表单值
xmlhttp.send(null);

//设置http头


//读取XML文件
function   readNewRecord(strdate){
var   nodebuffer   =   " " ;
nodebuffer   =   nodebuffer   + " <ul> ";

var   prognode   =   strdate.getElementsByTagName( "item ");
alert(prognode.length);
for(var   i=0;   i <prognode.length;   i++){
var   menunodeText   =   prognode[i].childNodes[1];
var   urlnodeText   =   prognode[i].childNodes[2];
alert(menunodeText);
nodebuffer   =   nodebuffer   + " <li> <a   href= ' "+   urlnodeText.text   +   " '> "+   menunodeText.text   + " </a> </li> ";
}

nodebuffer   =   nodebuffer   + " </ul> ";
document.write   (nodebuffer);
}
//-->
</script>
</body>
</html>


说明:就是动态读取XML文件中item的记录,写到一个 <ul> 中~,高手帮俺看看!

------解决方案--------------------