在调用加载XML方法的时候,要延迟些时间才能得到正确的值,不延迟就得不到正确值。
看了网络上操作XML的方法 都不需要延迟执行的。真是很纳闷。请求懂的朋友指点下。谢谢function xmlClass(){
this.fileName="workbook";
this.filePath="Db/";
}function Xml(){
//读取XML
this.requestXml = function(){
var xmlDoc; 
var xmlFile = this.filePath+this.fileName+".xml"; 
        if(window.ActiveXObject){  
            xmlDoc = new ActiveXObject('Microsoft.XMLDOM');  
            xmlDoc.async = false;  
            xmlDoc.load(xmlFile);  
        }else if (document.implementation&&document.implementation.createDocument){  
            xmlDoc = document.implementation.createDocument('', '', null);  
            xmlDoc.load(xmlFile);  
        }else{  
            return null;  
        } 
    return xmlDoc; 
}
}
Xml.prototype = new xmlClass();//类调用
var myXML = new Xml();
myXML.fileName = "workbook";
var XML = myXML.requestXml();
if(XML == null)
{ alert('浏览器不支持')}
else
{
//alert(list);只有加上这代码延迟了下面代码的执行,就能得到list的长度list.length=6,去掉这代码后,list.length = 0。是什么原因造成的呢
list = XML.getElementsByTagName("items");
alert(list.length)
}