goto next
如何通过jquery将一个td数据的总和加载到下一个tr的另一个td?请参阅https://jsfiddle.net/id10922606/y4wmhcw9/11/
答案 0 :(得分:0)
您可以执行类似
的操作
$(document).ready(function() {
var obj = {
val1: 0,
val2: 0
};
$('.row_val').find('.val1, .val2').each(function() {
obj[this.className] += +$(this).text() || 0;
});
var $sums = $('.rowsubvalue .sum');
$sums.eq(0).text(obj.val1.toFixed(2));
$sums.eq(1).text(obj.val2.toFixed(2));
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr class="row_val">
<td>
<div>Act/Proj</div>
<div>Rev. Bus./LRP</div>
</td>
<td>
<div class="val1">8.5</div>
<div class="val2">5.6</div>
</td>
<td>
<div class="val1">8.5</div>
<div class="val2">5.6</div>
</td>
<td>
<div class="val1">8.5</div>
<div class="val2">5.6</div>
</td>
</tr>
<tr class="variance_brdr rowsubvalue">
<td>
<div>Variance</div>
</td>
<td>
<div class="sum"></div>
</td>
<td>
<div class="sum"></div>
</td>
</tr>
</table>
&#13;
答案 1 :(得分:0)
这个怎么样:https://jsfiddle.net/y4wmhcw9/8/
$(document).ready(function() {
var sumval1 = 0;
var sumval2 = 0;
$('.row_val div.val1').each(function() {
sumval1 += Number($(this).html());
});
$('.row_val div.val2').each(function() {
sumval2 += Number($(this).html());
});
$('div.sum:eq(0)').html(sumval1);
$('div.sum:eq(1)').html(sumval2);
});