找到具有最大数量的tr

时间:2018-05-08 05:16:32

标签: jquery html

我有一张桌子

<table>
<thead>
<tr>
   <th colspan="2" rowspan="1">Col 1</th>
   <th  colspan="2" rowspan="1">Col 2</th>
</tr>
<tr>
   <th rowspan="1" colspan="1">Col 3</th>
   <th rowspan="1" colspan="1">Col 4</th>
   <th rowspan="1" colspan="1">Col 5</th>
   <th rowspan="1" colspan="1">Col 6</th>
</tr>
</thead>
<tbody>
</tbody>
</table>

我想找到有更多数量的&#39;的tr。请为我建议一个答案

1 个答案:

答案 0 :(得分:1)

这是真正的基础,但尝试这样的事情:

var rowWithHightestChildCount,
    currentHighestRowCount = 0;

$("thead>tr").each(function(){
    var childCount = $(this).children().length;

    if(childCount > currentHighestRowCount){
        currentHighestRowCount = childCount;
        rowWithHightestChildCount = $(this);
    }
})

console.log("Row", rowWithHightestChildCount);
console.log("Row Count", currentHighestRowCount);

var rowWithHightestChildCount 将包含具有更多 th 元素的元素