使用jQuery计算两个特定行之间的表行数 [英] Count number of table rows between two specific rows with jQuery

查看:75
本文介绍了使用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;

这篇关于使用jQuery计算两个特定行之间的表行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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