jquery - 为什么 jQueryeach() 不能在 Internet Explorer 中触发?

标签 jquery internet-explorer each

我有一个带有以下 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/

相关文章:

jquery - 处理跨域 jsonp 调用的 jQuery.ajax 错误

html - SVG 不在 IE11 上的 div 中心

html - Internet Explorer 不提供为登录页面保存凭据

javascript - jquery $.each 函数中的简单 if 语句未返回正确的值

Javascript 语法在 Safari/Webkit 中无效,但在 Chrome/Firefox 中工作正常

javascript - 使用 jQuery 动态添加和删除表列

javascript - 不符合宽高比的溢出图像

javascript - 伪类在 IE 中不适用于 jQuery Accordion

jquery - 在jquery每个循环中设置数据属性

javascript - 使用 jQuery 在并行树路径中查找 html 元素