使用jQuery计算两个特定行之间的表行数

问题描述:

<table>
  <tr id="parent_1">
    <td>Parent 1</td>
  </tr>
  <tr class="child">
    <td>Child 1</td>
  </tr>
  <tr class="child">
    <td>Child 2</td>
  </tr>
  ...
  <tr id="parent_2">
    <td>Parent2</td>
  </tr>
  ...
</table>

如何使用jQuery查找parent_1和parent_2之间的子行数?

How can I find the number of child rows between parent_1 and parent_2 using jQuery?

编辑:对不起,没有说明这只是一个例子,该表可以包含任意数量的父行,以及任意数量的子行

Sorry, didn't make it clear that this is just an example, the table could contain any number of parent rows, and any number of child rows

这会得到你想要的东西

var childCount = ($('#parent_2').get(0).rowIndex - $('#parent_1').get(0).rowIndex) - 1;