我有下表:
<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);
关于javascript - jquery 表中的搜索和条目计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13481460/