访问表的第 n 列 [英] Access nth column of table
本文介绍了访问表的第 n 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有以下结构和数据的表
I have a table with the following structure and data
<tr>
<td><input id="c1" type="checkbox"/></td>
<td>342</td>
<td>24</td>
<td>Jeff</td>
</tr>
<tr>
<td><input id="c2" type="checkbox"/></td>
<td>343</td>
<td>29</td>
<td>Libo</td>
</tr>
我想计算所有被检查的行的第三列的总值.所以假设上面的两行都被检查,第三列的值将是 24+29=53
I want to calculate total value of the third column of all rows, which are checked. So assuming both rows above are checked, the value of third column will be 24+29=53
推荐答案
var total = 0;
$("table tr:has(:checkbox:checked) td:nth-child(3)").each(function() {
total += parseInt($(this).text());
});
见这个fiddle.
这篇关于访问表的第 n 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文