1

Found a really weird problem with jQuery in IE7 today where it isn't finding selectors properly inside an element. Here's the HTML code:

<DIV id=firstVideoWrap>
    <OBJECT style="FLOAT: left" id=firstVideo width=300 height=300>
        <PARAM NAME="allowfullscreen" VALUE="true" />
        <PARAM NAME="movie" VALUE="http://vimeo.com/">
    </OBJECT>
</DIV>
<DIV id=secondVideoWrap>
    <OBJECT style="FLOAT: left" id=secondVideo width=300 height=300>
        <PARAM NAME="allowscriptaccess" VALUE="always" />
        <PARAM NAME="movie" VALUE=http://vimeo.com/moogaloop.swf />
        <PARAM NAME="wmode" VALUE="opaque" />
    </OBJECT>
</DIV>

and the relevant javascript:

console.log(jQuery("#firstVideo param").length);
console.log(jQuery("#firstVideoWrap param").length);
console.log(jQuery("#secondVideo param").length);
console.log(jQuery("#secondVideoWrap param").length);

It is giving the output:

5
2
5
3

Here it is in JSFiddle: http://jsfiddle.net/uGpUy/2/

It seems that IE isn't counting the number of param's on an object and instead is counting all param's on the entire page. While when I use the wrapping div it counts them correctly.

Also If I do:

jQuery("#secondVideo > param").length

It works correctly.

Is this a jQuery bug or something I've done wrong in my code?

EDIT: I've submitted a jQuery bug ticket for this: http://bugs.jquery.com/ticket/11646, will see how that progresses.


I don't know Swing or AWT well so I can't help much with that part.

You won't be able to access the local hard disk without signing the applet. That's a tricky process. To avoid going through that put the image in the JAR and use getResourceAsStream() to get to it.

Wrap everything in paint() in a try-catch and print out the exception if one occurs.

4

2 回答 2

1

它看起来是与<OBJECT />标签相关的错误。如果你用<OBJECT />标签替换你的<DIV />标签,它就像你想要的那样工作

2
2
3
3

我确实通过.children()<OBJECT />选择器上使用它来工作:

console.log(jQuery("#firstVideo").children("param").length);
console.log(jQuery("#firstVideoWrap param").length);
console.log(jQuery("#secondVideo").children("param").length);
console.log(jQuery("#secondVideoWrap param").length);

输出:

2
2
3
3

另一个注意事项:

该错误似乎在该.find()方法中,因为当我尝试使用它而不是.children()它返回时:

5
2
5
3
于 2012-04-25T15:37:14.873 回答
0

更重要的是,在 IE8 中,所有四个长度都是 0。使用jQuery("#secondVideo > param")也会产生 0...不知道为什么会发生。

于 2012-04-25T15:16:57.483 回答