且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更好地“找到父母"的方式如果语句

更新时间: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.