如何使用jquery查找列的总和 [英] how to find a sum of column using jquery
问题描述
大家好,我有2张桌子,一张父桌和一张桌子。一张儿童桌。
父表链接到子表,我有两列总金额&父母表中的总重量,
儿童表中包含个人数量&重量。
所以我想要的是个人金额和金额的总和。来自CHILD TABLE的权重将显示在PARENT TABLE中。另外,
请有人帮我提供代码吗?
我面临的问题是THE PARENT TABLE有不同的AMOUNTS&重量!
下面是我试过的代码,但问题是,每个父母都有一个孩子,因为有很多父母和他们。孩子,当我运行这个时,总量&总重量将返回所有父母和总和的总和。网格中存在的孩子。
Hello guys,i Have 2 tables,A parent table & a child table.
the parent table is linked to child table, i have two columns Total amount & total weight in PARENT TABLE,
the CHILD TABLE contains the individual amounts & weights.
so what i want is the sum of the individual amounts & weights from CHILD TABLE to be displayed in PARENT TABLE. also,
please can somebody help me with the code ?
the problem that im facing is THE PARENT TABLE has different set of AMOUNTS & WEIGHTS!
the below is the code of what i tried,but the problem is,each parent has a child,as there r many parents & child, when i run this,the Total amount & total weight will return the sum of all the parents & child present in the grid.
var theTotal = 0;
$(".child_amount_grid").each(function () {
theTotal += ($(this).val() == "" || isNaN($(this).val()) || $(this).val() == undefined) ? 0 : parseInt($(this).val());
});
$('.parent_totalamt_grid').html(theTotal);
theTotal = 0;
$(".child_weight_grid").each(function () {
theTotal += ($(this).val() == "" || isNaN($(this).val()) || $(this).val() == undefined) ? 0 : parseInt($(this).val());
});
$('.parent_totalwt_grid').html(theTotal);
推荐答案
( .child_amount_grid)。each(function(){
theTotal + =(
(".child_amount_grid").each(function () { theTotal += (
( this )。val()== || isNaN(
(this).val() == "" || isNaN(
( this )。val())||
(this).val()) ||
这篇关于如何使用jquery查找列的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!