在子选择器的jQuery文档中,我看到了这个注释:
注意:
$("> elem", context)选择器将在以后的版本中弃用.因此不鼓励使用其替代选择器.
我一直使用这种模式,通常是这样的:
$nodes.find('> children[something=morecomplicated] > somethingelse');
Run Code Online (Sandbox Code Playgroud)
但是,我不明白他们所指的"替代选择者"是什么.编写遍历上下文节点的直接子节点的选择器的正确方法是什么? 作为奖励,任何人都可以解释为什么这是折旧的?每个人都给予的所有替代品看起来都非常难看.
这里有一些事情,不工作:
// does not guarantee that '.child' is an immediate child
$nodes.find('.child > .grandchild');
// this will return empty array in recent jQuery
// and will return full list of children in older jQuery
$nodes.children('.child > .grandchild');
// Anything like this which forces you to split up the selector.
// This is ugly and inconsistent with …Run Code Online (Sandbox Code Playgroud)