gpt4 book ai didi

jquery - tablesorter jquery 获取过滤后数字列的总和

转载 作者:行者123 更新时间:2023-12-01 02:55:51 26 4
gpt4 key购买 nike

我正在使用 tablesorter jquery 进行开发,我的问题是:

有没有办法显示过滤后的数字列的总和?

例如:

++++++++++++
名字-金钱
+++++++++++
艾伦- 10
艾伦- 10
艾伦- 10
艾伦- 10
约翰- 10
约翰- 10
约翰- 10

金额:70

如果我过滤名称并只显示“alan”,我想得到这个:

++++++++++++
名字-金钱
+++++++++++
艾伦- 10
艾伦- 10
艾伦- 10
艾伦- 10

金额:40

感谢您的帮助:)

最佳答案

试试这个...这是来自 this demo 的 HTML :

<table class="tablesorter">
<thead>
<tr>
<th>Name</th>
<th>Money</th>
</tr>
</thead>
<tbody>
...
</tbody>

</table>Sum of Money: <span class="total"></span>

以及必要的脚本:

$('table')
.on('initialized filterEnd', function(){
var total = 0;
$(this).find('tbody tr:visible').each(function(){
// find money in 2nd column
total += parseFloat( $(this).find('td:eq(1)').text() );
});
$('.total').text(total);
})
.tablesorter({
theme: 'blue',
widgets: ['filter']
});

关于jquery - tablesorter jquery 获取过滤后数字列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22674636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com