IE8上的jQuery选择器路径错误

时间:2013-02-05 10:21:27

标签: javascript jquery

在IE8上,jQuery版本1.4.2为以下选择器路径返回0(当检查长度时)但是版本1.9.1返回1.

selectorPath = 'DIV#header + DIV > TABLE:first-child > TBODY:first-child > 
                TR:first-child > TD:first-child > TABLE:first-child > 
                TBODY:first-child > TR:first-child > TD:first-child > 
                TABLE:first-child > TBODY:first-child > TR:first-child > 
                TD:first-child > DIV:first-child + P + P + P + P + P + P 
                + P + P + P + P + P + P + P + P + P + P + P + P + P + P + 
                P + P + P + P + P + P + P + P + P + P + P + P + P + P + P 
                + P + P + P + P + P + P + H2 + P + P + P + P + P + P + P + 
                P + P';

$_1_4_2(selectorPath).length //returns 0

$_1_9_1(seelctorPath).length //returns 1

有人可以指出我确切的错误来解决这个问题,或者至少是版本1.4.2上可能相关的选择器路径错误的列表

1 个答案:

答案 0 :(得分:0)

尝试将它分成几块......

selectorPath = 'DIV#header + DIV > TABLE:first-child > TBODY:first-child > 
                    TR:first-child > TD:first-child > TABLE:first-child > 
                    TBODY:first-child > TR:first-child > TD:first-child > 
                    TABLE:first-child > TBODY:first-child > TR:first-child > 
                    TD:first-child > DIV:first-child + P + P + P + P + P + P 
                    + P + P + P + P + P + P + P + P + P + P + P + P + P + P + 
                    P + P + P + P + P + P + P + P + P + P + P + P + P + P + P 
                    + P + P + P + P + P + P + H2 + P + P + P + P + P + P + P + 
                    P + P';

    var half_len = Math.floor(selectorPath.length/2)                
    var first_part = selectorPath.substring(0, half_len);
    var second_part = selectorPath.substring(half_len, selectorPath.length);

    $_1_4_2(first_part).filter(second_part).length