簡體   English   中英

JavaScript-IE 9 XML textContent

[英]JavaScript - IE 9 XML textContent

下一個代碼在Firefox上運行良好,但是IE 9給出了udnefiend的結果:

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標准建議。 要求您使用跨瀏覽器兼容的標准屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM