问题描述
在jQuery中是否有一个内置函数,该函数可以让我将所有父级提升为具有特定ID的父级?我有一个嵌套很深的无序列表,如果要引用"li"之一,则需要找到所有父"li",直到根"ul".如果我使用parents(),它会给我所有父母以文档的根源.一种方法就是编写递归函数并检查父代的id,但是如果有内置的东西,我宁愿使用它.
Is there a built in function in jQuery that would allow me to get all the parents up to a parent with specific Id? I have a deeply nested unordered list, and if I have a reference to one of the "li" I need to find all parent "li" up to a root "ul". If I use parents() it gives me all parents up to a root of document. One way would be just to write recursive function and check for id of the parent, but if there is something built in I would rather use that.
推荐答案
直到的父母都应该工作为了那个原因.我认为您需要jQuery 1.4才能使用它.
Parents Until should work for that. I think you need jQuery 1.4 to use it though.
这篇关于jQuery:查找所有父母直至特定父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!