gpt4 book ai didi

jquery - 在 jQuery 中使用单个表达式选择同级的子级

转载 作者:行者123 更新时间:2023-12-01 00:05:21 25 4
gpt4 key购买 nike

是否可以使用与此类似的单个表达式来选择 jQuery 中当前上下文的同级的子级?

$('~ div > span', this)

不幸的是,这对我不起作用,所以我不相信 jQuery 支持表达式中的这种类型的链接。然而,我能够使以下方法发挥作用:

$('> span', $('~ div', this))


$(this).siblings('div').children('span')

我正在寻找一种使用以下 API 调用来获取 sibling 的 child 的方法,或者寻求解释为什么这是不可能的:

jQuery( expression, context )

最佳答案

我知道这有点旧,但我想我会回答,以防其他人尝试这样做。 find()是最好的方法来做到这一点

$(this).siblings('div').find('span');

希望有帮助

关于jquery - 在 jQuery 中使用单个表达式选择同级的子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1019702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com