更新时间:2023-02-16 11:02:45
哇,您可以使用 parents()
方法.
wow, you can use closest
or parents()
method.
closest( selector )
获取与选择器匹配的第一个元素,从当前元素开始,一直扩展到DOM树.
closest( selector )
Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.
parents( [selector] )
获取当前匹配元素集中每个元素的祖先,可以选择使用选择器进行过滤.
parents( [selector] )
Get the ancestors of each element in the current set of matched elements, optionally filtered by a selector.