jQuery:如何计算“显示"元素的数量?不是“没有"吗? [英] jQuery: How to count the number of elements which "display" isn't "none"?

查看:160
本文介绍了jQuery:如何计算“显示"元素的数量?不是“没有"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用show()hide()来显示和隐藏表中的行.

I use show() and hide() to show and hide rows in a table.

我如何计算未隐藏的行数(更准确地说,是具有display!= none的行)?

How could I count the number of non-hidden rows (more accurately, rows with display != none) ?

请注意:

$('tr:visible').length

无效,因为如果表本身具有display=none,则结果将始终为0.

won't work because if the table itself has display=none, the result will always be 0.

推荐答案

根据行的实际CSS属性过滤行:

Filter your rows based on their actual CSS property:

$('tr').filter(function() {
    return $(this).css('display') !== 'none';
}).length;

这篇关于jQuery:如何计算“显示"元素的数量?不是“没有"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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