脚本:
function subTotal3(param)
{
var product_quantity = 0;
var product_price = 0;
var gst_amount = 0;
var sub_total = 0;
var total_qty = 0;
var grand_total = 0;
var splitty;
var unit_price;
$('input[id=qty_'+param+']').each( function( k, v ) {
/*starts here*/
product_quantity = parseInt ( $(this).val() ) ? parseInt ( $(this).val() ) : 0;
product_price = $(this).parent().prev().text()? $(this).parent().prev().text():0;
/*ends here*/
splitty = product_price.split('RM');
unit_price = splitty[1];
sub_total = parseFloat (unit_price * product_quantity);
$(this).parent().next().val(sub_total);
$(this).parent().next().text(sub_total);
total_qty += product_quantity;
grand_total += sub_total;
});
alert(total_qty);
$('.qty_1').text(total_qty);
$('.total').text(grand_total);
}
这是输出(注意总计下的值):
“总计”下的值显示当前所选项目的总数量和小计。据说,它应该显示这两项的总计。
我猜想,声明 var total_qty = 0;
、var grand_total = 0;
导致它,因此我声明它们而不分配值 0
然后它显示 Amount
的 NaN
。我尝试将 total_qty += Product_quantity;
放在 $.each 循环之外,但出现同样的问题。请问如何添加总数量和总金额?
最佳答案
尝试在输入中添加类,例如class="qty"
。然后将 $('input[id=qty_'+param+']')
替换为 $('.qty')
关于javascript - 总计和总数量未显示所有项目的添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792985/