Sibling +选择器在使用jQuery时在IE7中不工作 [英] Sibling + selector does't work in IE7 when using jQuery
本文介绍了Sibling +选择器在使用jQuery时在IE7中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用jQuery选择兄弟元素,它在IE7中不起作用。
Trying to select a sibling element using jQuery and it doesn't work in IE7.
以下是我的示例代码: http:// jsfiddle .net / y7AHz / 6 / (点击运行查看结果)
Here is my sample code: http://jsfiddle.net/y7AHz/6/ (click Run to see result)
var numberOfListItems = $("#txtInput + ul.ulContainer li").length;
$("#output").text(numberOfListItems);
在IE8,Firefox,Safari中它的工作(#of list itmes from 3) p>
In IE8, Firefox, Safari it works(# of list itmes comes out to 3).
推荐答案
这是一个。而是使用 .next()
,这相当于 +
或下一个相邻的
选择器和 .find()
。它更冗长,但它适用于IE6 +:
This is a known bug with sizzle (the selector engine underneath jQuery) in IE6 and 7. Instead, use .next()
, which is equivalent to the +
or next adjacent
selector, and .find()
. It's more verbose, but it works in IE6+:
var numberOfListItems = $("#txtInput").next(".ulContainer").find("li").length;
这篇关于Sibling +选择器在使用jQuery时在IE7中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文