jQuery parent(),parents()和closest()函数之间的区别 [英] Difference between jQuery parent(), parents() and closest() functions
问题描述
我已经使用jQuery一段时间了.我想使用parent()
选择器.我还想出了closest()
选择器.找不到它们之间的任何区别.有没有?如果是,那是什么?
I have been using jQuery for a while. I wanted to use the parent()
selector. I also came up with the closest()
selector. Could not find any difference between them. Is there any? If yes, what?
parent()
,parents()
和closest()
有什么区别?
推荐答案
closest()
选择与选择器匹配的第一个元素,向上 从DOM树中.从当前元素开始并向上移动.
closest()
selects the first element that matches the selector, up from the DOM tree. Begins from the current element and travels up.
parent()
选择一个(向上一级(向上一级))DOM树元素.
parent()
selects one element up (single level up) the DOM tree.
parents()
方法类似于
parents()
method is similar to parent()
but selects all the
matching elements up the DOM tree. Begins from the parent element and travels up.
这篇关于jQuery parent(),parents()和closest()函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!