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

后端 未结 2 1055
忘了有多久
忘了有多久 2020-12-30 12:31

So the short version of this is: Can I traverse only the elements within the matched element of the selectors before the each()? Or is there a simpler way of ge

2条回答
  •  甜味超标
    2020-12-30 12:44

    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

提交回复
热议问题