Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Internet Explorer独占Javascript错误。无法获取属性的值';子节点';_Javascript_Html_Internet Explorer 9 - Fatal编程技术网

Internet Explorer独占Javascript错误。无法获取属性的值';子节点';

Internet Explorer独占Javascript错误。无法获取属性的值';子节点';,javascript,html,internet-explorer-9,Javascript,Html,Internet Explorer 9,回答:从XML文件中删除头信息解决了这个问题。他太棒了 以下代码适用于Firefox和Chrome,而不是IE 我得到了错误 SCRIPT5007: Unable to get value of the property 'childNodes': object is null or undefined. line 106, character 3` 第106行是排序函数中的第一行,它以“var aCat=a.getElementsByTagName”开头 正在排序的节点中没有一个是空的,

回答:从XML文件中删除头信息解决了这个问题。他太棒了

以下代码适用于Firefox和Chrome,而不是IE

我得到了错误

SCRIPT5007: Unable to get value of the property 'childNodes': object is null or undefined.  
line 106, character 3`
第106行是排序函数中的第一行,它以“var aCat=a.getElementsByTagName”开头

正在排序的节点中没有一个是空的,尽管在xml文件中的同一个节点中,有一些是空的节点(即im排序打开,没有一个是空的,但有些人没有电话号码或呼机号码等,因此其中一些是空的)

当我尝试将排序放入一个try-catch块(即没有读取任何节点)时,它们都抛出了一个异常。(同样,Chrome和Firefox使用了try-catch块)

我被难住了,有什么想法吗

function populateSection(listType, tableID ) {

if (window.XMLHttpRequest) {/*code for IE7+, Firefox, Chrome, Opera, Safari*/ xmlhttp=new XMLHttpRequest(); }
else {/* code for IE6, IE5*/ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

var table = tableID;
var list = listType;

xmlhttp.open("GET",'contactlist.xml',false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

var xmlGet = xmlDoc.getElementsByTagName("PERSON");
var x = Array.prototype.slice.call(xmlGet,0);

x.sort(function(a,b) {
    var aCat = a.getElementsByTagName("LASTNAME")[0].childNodes[0].nodeValue;
    var bCat = b.getElementsByTagName("LASTNAME")[0].childNodes[0].nodeValue;
    if (aCat > bCat) return 1;
    if (aCat < bCat) return -1;
    return 0;
});

//then cycle through the array, adding table rows for each node
...}
函数populateSection(listType,tableID){
if(window.XMLHttpRequest){/*IE7+、Firefox、Chrome、Opera、Safari的代码*/xmlhttp=new-XMLHttpRequest();}
else{/*IE6、IE5的代码*/xmlhttp=newActiveXObject(“Microsoft.xmlhttp”);}
var table=tableID;
var list=listType;
open(“GET”,'contactlist.xml',false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var xmlGet=xmlDoc.getElementsByTagName(“个人”);
var x=Array.prototype.slice.call(xmlGet,0);
x、 排序(功能(a、b){
var aCat=a.getElementsByTagName(“LASTNAME”)[0].childNodes[0].nodeValue;
var bCat=b.getElementsByTagName(“LASTNAME”)[0]。子节点[0]。节点值;
如果(aCat>bCat)返回1;
如果(aCat
编辑: 以下是xml文件的一部分:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CONTACTLIST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <PERSON>
        <LASTNAME>ALLEN</LASTNAME>
        <FIRSTNAME>Korrie</FIRSTNAME>
        <EMAIL>redacted@evms.edu</EMAIL>
        <PHONE>123456</PHONE>
        <LIST>main</LIST>
    </PERSON>
    <PERSON>
        <LASTNAME>BUESCHER</LASTNAME>
        <FIRSTNAME>Chris</FIRSTNAME>
        <EMAIL>redacted</EMAIL>
        <LIST>main</LIST>
    </PERSON>
    <PERSON>
        <LASTNAME>BUESCHER</LASTNAME>
        <FIRSTNAME>Steve</FIRSTNAME>
        <EMAIL>redacted@evms.edu</EMAIL>
        <PHONE>123456</PHONE>
        <LIST>main</LIST>
        <LABOTHER>123456</LABOTHER>
        <BEEPER>123456</BEEPER>
    </PERSON>
    <PERSON>
        <LASTNAME>CHARTERS</LASTNAME>
        <FIRSTNAME>Michelle</FIRSTNAME>
        <EMAIL>redacted@evms.edu</EMAIL>
        <PHONE>123456</PHONE>
        <LIST>main</LIST>
    </PERSON>

艾伦
科里
redacted@evms.edu
123456
主要的
布舍尔
克里斯
编辑
主要的
布舍尔
史蒂夫
redacted@evms.edu
123456
主要的
123456
123456
特许
米歇尔
redacted@evms.edu
123456
主要的

由于没有显示您的XML,我们将很难找出代码在哪里被破坏,但下面是一些猜测:

var x=Array.prototype.slice.call(xmlGet,0) 这在IE8中不起作用,在IE9中可能有问题。尝试
alert(x)
并查看对象是否为
null


如果您的XML以
或类似的开头,这实际上可能会破坏IE。我不知道为什么。尝试删除它并查看它是否有效。

错误似乎会告诉您出了什么问题:
对象为null或未定义
。在使用该对象之前,请尝试添加一个检查,以确保该对象存在(且不为null)。为什么不使用jQuery之类的工具而使用这种困难的方法?请向我们展示您的xml文件。IE以不完全解析所有内容而闻名。这是为了工作,所以这是不可谈判的。我确实有一个元标记强制IE9渲染。添加了xml文件的一部分。删除xml文件中的头信息并不能修复此问题。当slice语句之后出现I
alert(x)
时,对象在Chrome和FF中不为null。在IE中,我得到一个错误
对象不支持此属性或方法
删除标题信息确实有效。这很痛苦,因为每次保存xml文件时Excel都会将其添加回去,所以现在我必须向管理员助理演示如何直接编辑xml文件,而不是在Excel中进行编辑。