我从 javascript 调用 Web 服务,然后解析 xml 并呈现表。在 Firefox 中一切都很好,但在 IE 中却是另一回事。
问题似乎出在这一行
var count = result.childNodes[0].getAttribute('Count');
是否有一种 IE 友好的方式来获取 javascript 中的 xml 属性?
其余代码工作正常。但不幸的是我需要那个计数。
最佳答案
这适用于 IE 7:
x=xmlDoc.getElementsByTagName("book")[0].attributes;
document.write(x.getNamedItem("category").nodeValue);
book 是元素名称,category 是属性名称。我在 W3Schools 上找到了这个示例:
关于javascript - 在 Internet Explorer 中解析 xml 文档时 getAttribute 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1374447/