JavaScript - IE 9 XML textContent

JavaScript - IE 9 XML textContent

本文关键字:XML textContent IE JavaScript      更新时间:2023-09-26

下面的代码在Firefox下运行良好,但是ie9给出了错误的结果:

var url = "http://www.w3schools.com/xml/note.xml";
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function(event){ processRequest(event,xmlhttp); };
xmlhttp.send();
function processRequest(event,xmlhttp) {
    if(xmlhttp.readyState != 4) return;
    if(xmlhttp.status != 200) return;
    var responseXML = xmlhttp.responseXML;
    alert(responseXML.getElementsByTagName("note")[0].getElementsByTagName("to")[0].textContent);
}

如何在IE9中获得XML元素的textContent ?

要从XML DOM对象访问任何节点的值,请使用属性

dom_node.nodeValue;

textContent不是W3C标准推荐。要求您使用跨浏览器兼容的标准属性