jQuery选择器过滤掉元素 [英] jquery selector to filter out th elements

查看:77
本文介绍了jQuery选择器过滤掉元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

var rows = $table.find('tbody > tr').get();

这将选择所有行.但是,并非所有表都明确定义了thead和tbody,因此我需要过滤 out 任何具有.children('th')

This selects all rows. However, not all tables have thead and tbody explicitly defined, so I need to filter out any rows that have .children('th')

推荐答案

编辑:我假设您要过滤 out 包含<th>元素的行.如果您想只以 行结尾,那么就去掉:not()部分.

I'm assuming you wanted to filter out the rows that have <th> elements. If you wanted to end up with only those rows, then just get rid of the :not() part.

这将为您提供表中没有后代<th><tr>个元素.

This will give you <tr> elements in the table that do not have a descendant <th>.

var rows = $table.find('tr:not(:has(th))').get();

  • http://api.jquery.com/not-selector/
  • http://api.jquery.com/has-selector/
    • http://api.jquery.com/not-selector/
    • http://api.jquery.com/has-selector/
    • 请注意,这还将考虑嵌套表.如果将有带有<th>标记的嵌套表,请尝试以下操作:

      Note that this will also give consideration to nested tables. If there will be nested tables with <th> tags, try this:

      var rows = $table.find('tr:not(:has( > th))').get();
      

      ...这应将对<th>标记的考虑仅限于直系子代.

      ...which should limit the consideration of the <th> tags to immediate children.

      这篇关于jQuery选择器过滤掉元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆