如何计算搜索表上匹配结果的数量 [英] How to count the number of matching results on a search table

查看:189
本文介绍了如何计算搜索表上匹配结果的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个带搜索功能的HTML表格。我想在搜索时显示匹配结果金额,以及搜索字段为空时的总金额。我尝试使用 .length 但它计算了所有包含隐藏行的行。

I have made a HTML table with a search function. I want to display the matching result amount when searching, and the total amount when search field is blank. I tried with .length but it counted all rows included hidden ones.

如何只计算显示的行数?

How can I count only the displayed rows?

jsfiddle

我目前正在使用此代码:

I'm currently using this code:

//testing: count number of results
var rowCount = $('#search-table >tbody >tr').length;
document.getElementById('count').innerHTML = rowCount;

提前谢谢。

推荐答案

搜索后你需要找到只有可见tr元素的长度。您可以使用:visible :not(:hidden)选择器来实现此目的:

You need to find the length of only visible tr elements after search. you can use :visible or :not(:hidden) selector to achieve this:

var rowCount = $('#search-table >tbody >tr:visible').length;

工作演示

这篇关于如何计算搜索表上匹配结果的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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