可能重复:
What is the new proper way to use a child selector with a context node in jQuery?儿童选择弃用
从jQuery文档:
注:$( “> ELEM”,上下文)选择将在未来版本中已弃用。因此,它的使用不再使用替代选择器。
http://api.jquery.com/child-selector/
什么会是这方面alternative selector
?
可能重复:
What is the new proper way to use a child selector with a context node in jQuery?儿童选择弃用
从jQuery文档:
注:$( “> ELEM”,上下文)选择将在未来版本中已弃用。因此,它的使用不再使用替代选择器。
http://api.jquery.com/child-selector/
什么会是这方面alternative selector
?
$(context).children('elem')
也$("> elem", context)
已被弃用,但$(context+" >elem")
和$("parent>child")
不
$('parent').children('childrenelements')
是我的猜想:)
但正如其他海报说,它仅适用于一个孩子的情况下直接搜索。
例如,如果上下文是一个元素,你可以使用选择该元素,而不是将其指定为背景的。因此,而不是:
var main = $('#Main');
var mainDivs = $('> div', main);
你可以使用:
var mainDivs = $('#Main > div');
这将只是我一个jQuery对象为“父” /“工作的事实工作语境”。 – PeeHaa
我只是碰到了同样的问题来了,我是在一个函数中,没有上述的真的帮了我。 .find似乎做了诡计。这是OIF是怎么回事有用的例子:
$('selectedcontext').first(function(){
// perform operations on selectedcontext for ex:
if($(this).hasClass('someclass')){
$(this).find('textarea').val();
}
});
这与'$(“> elem,context)'不一样。因为你的代码会检查元素的所有后代,而不仅仅是直接的后代。 – PeeHaa
这就是我想要因此直接孩子选择'>' – PeeHaa