我有一个包含大量信息的表,其中一个是充满货币值的列。它看起来像下面这样。
$23.21
$347.34
$3,200,884.00
我可以在服务器端添加值,但是使用过滤器,我不想再次访问服务器来获取信息。如何将这些值相加,以便在表格底部进行总计?
棘手的部分是,根据过滤器,我显示或隐藏某些值,因此我只想合计可见的货币值。
最佳答案
类似这样的东西(在不知道实际 html 的情况下无法精确)
var total = 0;
// the selector must be adjusted to the actual html
$('td.price:visible').each(function(){
var value = $(this).text().slice(1).replace(/,/g,'');
total += +value;
});
// use the total variable here to display it somewhere in your page
关于jquery - 从可见表列添加美元值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26549099/