我有一个具有以下XML的变量result
:
<Properties>
<Property>
<Name>Title</Name>
</Property>
</Properties>
然后,我将jQuery 1.4.3与
each()
一起使用:$('Property', result).each(function () {
var name = $('Name', this).text();
alert("Name: " + name);
});
由于某种原因,该代码无法在IE8下触发,但是在Firefox 3.6和Chrome 7上可以正常工作。我试图找到这种情况下的错误报告,但仅发现了旧版jQuery的问题。
有任何想法吗?
最佳答案
这是由IE中的错误引起的:
if ((properties.length == 0) && (jQuery.browser.msie)) {
// IE screwing up
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(result);
result = xmlDoc;
properties = $('Property', result);
}
properties.each(function () {
var name = $('Name', this).text();
alert("Name: " + name);
});
好消息-IE9中不会发生。 (感谢this SO answer)。
关于jquery - 为什么jQuery each()不使用Internet Explorer触发?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4131264/