Using jquery to get per row totals and grand total of table

梦想与她 提交于 2019-11-30 07:26:09
PetersenDidIt

You are trying to set your context incorrectly try this:

function findTotals() {
    $("tbody tr").each(function() {
        row_total = 0; 
        $("td:not(.total) input:text",this).each(function() {
           row_total += Number($(this).val());
        }); 
        $(".total :input:text",this).val(row_total);
    });

}

For more information about the context check out the jquery docs: http://docs.jquery.com/Core/jQuery#expressioncontext

There can be two parameters for a selector. The second parameter is the context htat that the search is to take place in. Try something like the following: $('#tableID tbody tr).each(function(){ //now this is a table row, so just search for all textboxes in that row, possibly with a css class called sum or by some other attribute $('input[type=text]',this).each(function(){ //selects all textbosxes in the row. $(this).val() gets value of textbox, etc. }); //now outside this function you would have the total //add it to a hidden field or global variable to get row totals, etc. });

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!