如何使用 jQuery 选择 $(this) AND $(this) > child?

Posted

技术标签:

【中文标题】如何使用 jQuery 选择 $(this) AND $(this) > child?【英文标题】:How to select $(this) AND $(this) > child with jQuery? 【发布时间】:2012-08-18 22:34:07 【问题描述】:

无法完全弄清楚这一点。如果我使用:

$('> .someClass', this);

它将选择this > .someClass,但我想选择this AND this > child

试过

  $(this+'> .someClass', this);
//AND
 var currentEl = $(this);
  $(currentEl, currentEl+'> .someClass')

任何帮助将不胜感激。

【问题讨论】:

【参考方案1】:

使用andSelf()

$(this).find('> .someclass').andSelf();

andSelf() documentation

【讨论】:

【参考方案2】:

您可以使用.andSelf() 函数将this 添加到匹配元素的集合中,如下所示:

$(this).find('> .someclass').andSelf();

【讨论】:

以上是关于如何使用 jQuery 选择 $(this) AND $(this) > child?的主要内容,如果未能解决你的问题,请参考以下文章