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

后端 未结 2 1054
忘了有多久
忘了有多久 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 13:04

    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. });

提交回复
热议问题