0

我有一个具有以下结构的 html 表:

<table>
<tbody>
  <tr><th>heading1</th></tr>
  <tr style="display: none"> <td>data1</td></tr>
  <tr style="display: none"> <td>data1</td></tr>
</tbody>

<tbody>
  <tr><th>heading2</th></tr>
  <tr> <td>data1</td></tr>
  <tr style="display: none"> <td>data1</td></tr>
</tbody>
</table>

我正在寻找一种方法来选择该表中包含标题的行,但其所有兄弟姐妹都被隐藏,在此示例中,标题2 不会被选中,因为只有一行被隐藏。

4

3 回答 3

2

我认为这应该这样做:

$("th").filter(function(){
    return !$(this).parent().nextAll().is(":visible");
});

http://jsfiddle.net/4fpgs/

于 2013-01-06T22:32:53.277 回答
1
var tr = $('tr:first-child').filter(function() {
  return $(this).siblings(':hidden').length == $(this).siblings().length;
});

示例:http: //jsfiddle.net/u6Qj5/1/

于 2013-01-06T22:33:40.807 回答
0
$('table th').filter(function() {
  var $tr = $(this).parent().siblings('tr');
  return $tr.filter(':hidden').length == $tr.length;
}).parent();
于 2013-01-06T22:30:00.447 回答