jquery计算和

来源:互联网 发布:拉格朗日插值算法程序 编辑:程序博客网 时间:2024/06/05 19:15
$('#btnsum').click(function () {
                var sl = tj + 3;
                $('#Tb2').find('tr').slice(1).each(function () {
                    var str1 = 0; //一行中的列组合参数
                    $(this).find('td').slice(1, sl).each(function () {
                        str1 += $(this).children().eq(0).val() - 0;
                    })
                    $(this).children().eq(sl).children().eq(0).attr('value', str1); //总计
                })
            })


$('按钮id').click(function () {
                var sl = tj + 3;//列的最大值
                $('#Tb2').find('tr').slice(1).each(function () {
                    var str1 = 0; //一行中的列组合参数  定义为数字类型的
                    $(this).find('td').slice(1, sl).each(function () {
                        str1 += $(this).children().eq(0).val() - 0;  //减0是为了将获取到的值转换成数字类型
                    })
                    $(this).children().eq(sl).children().eq(0).attr('value', str1); //总计 将总和添加到合计列
                })
            })