如何对 2 个不同的(类元素)总值求和?
示例:http: //jsfiddle.net/x7QuB/
var total_listed=[0,0];
var total_sold=[0,0];
$(document).ready(function(){
var $dataRows=$("#sum_table tr:not('.totalColumn, .titlerow')");
$dataRows.each(function() {
$(this).find('.DataListed').each(function(i){
total_listed[i]+=parseInt( $(this).html());
});
$(this).find('.DataSold').each(function(i){
total_sold[i]+=parseInt( $(this).html());
});
});
$("#sum_table td.totalColListed").each(function(i){
$(this).html("$"+total_listed[i]*2);
});
$("#sum_table td.totalColSold").each(function(i){
$(this).html("$"+total_sold[i]*3);
});
});
在“ .totalColListed
”下的一列中,我有所有列出的值的总和,而在其他 td 元素“ .totalColSold
”中,我有所有已售商品的总和。
如何将总和.totalColListed+.totalColListed
放入新元素(td/div/etc)中,例如 div " .total
" ?
先感谢您。