我有一个带有以下 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 - 为什么 jQueryeach() 不能在 Internet Explorer 中触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4131264/