【问题标题】:Grand total and total quantity not showing adding for all items总计和总数量未显示为所有项目添加
【发布时间】:2016-01-14 15:13:54
【问题描述】:

脚本:

 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 然后它显示 NaNAmount。我尝试将total_qty += product_quantity; 放在 $.each 循环之外,但同样的问题。请问总数量和总金额如何相加?

【问题讨论】:

  • @Lola,这正是问题所在...我用普通类替换了它,然后是特定的 id,然后它就起作用了!

标签: javascript jquery arrays


【解决方案1】:

尝试在您的输入中添加类,例如class="qty"。然后将$('input[id=qty_'+param+']') 替换为$('.qty')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多