jQuery:计算表中的行数 [英] jQuery: count number of rows in a table

查看:167
本文介绍了jQuery:计算表中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery计算表中的tr元素数量?

How do I count the number of tr elements within a table using jQuery?

我知道有一个类似问题,但我只想要总计行。

I know there is a similar question, but I just want the total rows.

推荐答案

使用将选择所有行并占用长度的选择器。

Use a selector that will select all the rows and take the length.

var rowCount = $('#myTable tr').length;

注意:这种方法还会计算每个嵌套表的所有tr!

Note: this approach also counts all trs of every nested table!

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

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