简体   繁体   English

为什么jQuery的parent / closest(selector)函数在IE8中表现不同?

[英]Why does jQuery's parents/closest(selector) functions behave differently in IE8?

I have a jQuery script that works perfectly fine in Chrome 11 and Firefox 4, but it appears to be broken in IE8. 我有一个jQuery脚本,可以在Chrome 11和Firefox 4中正常运行,但在IE8中似乎已损坏。 It appears to be related to the use of the jQuery parents() function with a selector. 它似乎与使用带有选择器的jQuery parent()函数有关。 It does not return any elements when run in IE8. 在IE8中运行时,它不返回任何元素。

I've created a simplified version of my problem which shows the same symptoms over at jsFiddle , to prevent a big chunk of code here. 我创建了问题的简化版本, 在jsFiddle上显示了相同的症状,以防止在此处出现大量代码。

Can anybody tell me what might be going on here? 有人可以告诉我这里会发生什么吗?

UPDATE: Using closest() seems to result in similar behavior, but seems to be more suitable in this case. 更新:使用closest()似乎会导致类似的行为,但在这种情况下似乎更合适。

Do the top level elements have to be sections? 顶层元素必须是部分吗? It looks like you are running into one of the areas where the lack of support for HTML5 in IE8 is limiting you. 似乎您正在进入IE8中对HTML5缺乏支持的局限性之一。 If you change the sections to divs, the code works as is. 如果将节更改为div,代码将按原样工作。

Section support in browsers. 浏览器中的部分支持。

Looking at the selectors in your jsFiddle, I was able to get it to work fine in IE8 if I just got rid of the second part of the selector. 查看jsFiddle中的选择器,如果我摆脱了选择器的第二部分,我就能使其在IE8中正常工作。

$(document).ready( function(){
     $('a[data-detailed]').live('click', function(event){
        var a = $(this);
        var key= a.attr('data-detailed');

        $(".detailedOverview[data-detailed="+key+"]").slideToggle('fast');
        $(".masterOverview").slideToggle('fast');
        event.preventDefault();   
    });

    $('a[href=#back]').live('click', function(event){
        var a = $(this);
        var detailedOverview= a.parents("[data-detailed]");

        $(".masterOverview").slideToggle('fast');         
        detailedOverview.slideToggle('fast');

        event.preventDefault();   
    });
});

In each of your selectors you had a ", fileparent" after the selector. 在每个选择器中,选择器后都有一个“ fileparent”。 It is not necessary to specify the parent like this and getting rid of it works. 不必像这样指定父级,并且摆脱它是可行的。 In fact you can get rid of fileparent all-together. 实际上,您可以完全摆脱fileparent。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM