日期:2014-05-17  浏览次数:20508 次

js读取xml 文件问题

  function changeSelectByPart()
        {
            var xmlDoc=null;
           if (window.ActiveXObject) {  //IE浏览器
                    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  
                    xmlDoc.async=false;  
                    xmlDoc.load("App_Data/ChildFunction.xml");
                }  //其他浏览器FIREFOX,CHROME,SAFARI 
              else if(document.implementation && document.implementation.createDocument)
              {
                    var xmlhttp = new window.XMLHttpRequest();
                    xmlhttp.open("GET", "ChildFunction.xml", false);
                    xmlhttp.send(null);
                    xmlDoc = xmlhttp.responseXML;
              }
              else
              {
                xmlDoc = null;
              }
      xmlDoc.load("App_Data/ChildFunction.xml");+$("#"+contentID+"DDL_Part").find("option:selected").text()
           
          
          var nodes = xmlDoc.selectNodes("//ChildFunction/"+$("#"+contentID+"DDL_Part").find("option:selected").text());
            

           alert(nodes.text);
         }



页面上两个下拉选框,分别夹在不同的xml节点,有层级关系。
根据第一个ddl 的选项变化而js加载xml文件里相应层级下的子级xml节点名字到ddl 里。
上面我写的代码,路径没有问题,节点也没有问题,但是谷歌报错:
Object #<Document> has no method 'selectNodes' 

就是倒数第二段js 报错,求解释。
------解决方案--------------------
如果一个方法行不通,就换个方法