javascript - jquery 表中的搜索和条目计数

标签 javascript jquery

我有下表:

<table>
    <tr>
        <th>Alarm</th>
    </tr>
    <tr>
        <td>OK</td>
    </tr>
    <tr>
        <td>Missing</td>
    </tr>
    <tr>
        <td>OK</td>
    </tr>
</table>

我想像这样计算这个表中的行
确定 = 2
缺失 = 1

但我不知道如何使用 jQuery 来做到这一点,应该仅为警报列指定选择器,因为我还有其他列包含 ok 和 Missing

注意:我想计算表中特定列的行数,仅用于警报列 alaram 列包含 2 个正常列和 1 个缺失列。

最佳答案

假设Alarm是第一列:

var okCount = $('td:contains("OK")').filter(function() {
    return $(this).index() == 0;
}).length;
var missingCount = $('td:contains("Missing")').filter(function() {
    return $(this).index() == 0;
}).length;

console.log('okCount: ' + okCount);
console.log('missingCount : ' + missingCount);​

​Live DEMO

关于javascript - jquery 表中的搜索和条目计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13481460/

相关文章:

jquery 将 div 移到其他之上

java - 将 jquery datepicker 集成到 jsf 中

javascript - 使用Flask和JQuery,如何在 "POST"方式中通过 "sexy"方法删除一条记录?

javascript - 是否可以在函数中使用非全局变量?

javascript - sweetalert 2 上有超过 2 个按钮

javascript - 是否可以让 JqGrid 向服务器发送 JSON 查询字符串?

jquery - html表格的对齐问题

javascript - 是否可以使用 React-strap 构建渐进式 Web 应用程序?

javascript - 如何打印到屏幕 - "console.log is not a function"

javascript - 为函数创建新上下文