Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何显示每个部门的小计_Jquery - Fatal编程技术网

Jquery 如何显示每个部门的小计

Jquery 如何显示每个部门的小计,jquery,Jquery,我有一个计算总计和小计的函数。我这里的问题是我想显示每个部门的小计,但它将是相同的输出。我希望标题1小计为37.00,标题2小计为99.00。这是屏幕截图 这是我的密码 $('.pricing_level').on('change', function(e){ var pricing_level_id = e.target.value; var customer_id = $('.customer ').val(); $('tbody.subcontent tr').e

我有一个计算总计和小计的函数。我这里的问题是我想显示每个部门的小计,但它将是相同的输出。我希望标题1小计为37.00,标题2小计为99.00。这是屏幕截图

这是我的密码

$('.pricing_level').on('change', function(e){
    var pricing_level_id = e.target.value;
    var customer_id = $('.customer ').val();

    $('tbody.subcontent tr').each(function(){
        var item_id =  $(this).closest('tr').find(".details_itemid").val();
        var category_id = $(this).closest('tr').find(".details_category_id").val();
        var subcategory_id = $(this).closest('tr').find(".details_subcategory_id").val();
        var that = this;

        $.get('/dev/api/itempricinglevel?item_id=' + item_id + '&pricinglevel_id=' + pricing_level_id, function(itempricinglevel){
            var std = parseFloat(itempricinglevel.std);
            var min = parseFloat(itempricinglevel.min);
            var max = parseFloat(itempricinglevel.max);

            $(that).closest('tr').find('.details_unitprice').val(std);

            //Here's the code to display the sub-total in every division
            var d_qty = $(that).closest('tr').find(".details_qty").val();
            var d_netprice  = $(that).closest('tr').find(".details_netunitprice").val();
            var total = d_qty * d_netprice;
            var totalAmt = total.toFixed(2);

            $(that).closest('tr').find(".details_total").val(totalAmt);
            grandtotal();
            var thisloc = $(that).parent().parent().parent().parent().find('.total');
            var inloc = $(that).parent().parent().parent().parent().find('.stotal');
            var eachloc =  $(that).parent().parent().parent().find('.details_total');
            subtotal(thisloc, eachloc, inloc);
            //------------------------------------------------------------ 
        })

    })
})
这是我的小计函数

function subtotal(thisloc, eachloc, inloc){ 
    var headertotal = 0;
    eachloc.each(function(){ 
        var price = $(this).val();
        headertotal += parseFloat(price);
        $(thisloc).text((headertotal).toFixed(2));
        $(inloc).val((headertotal).toFixed(2));
    });
}
下面是sub total的HTML代码

$('tbody.content').prepend('<div class="groupborder" style="border-color:#333333;"><tr><td> \
            <table class="tables_details" style="width:100%;">\
              <th id="groups" data-id="'+headcount+'" style="background-color: #333333; width: 1250px;" > \
                <label style="display:inline-block;float:left; margin-left:900px; width:60px; font-weight: bold; color:#FFFFFF;">Sub-total: </label> \
                <label class="head" style="display: block; margin-left: -930px; float: left; font-weight: bold; color:#FFFFFF;">HEADER '+headcount+'</label> \
                <input type="text" name="header_name[]" class="edit-input" style="height: 20px; display: none; margin-left: -930px; float: left; padding-left:5px;" value="HEADER '+headcount+'"/> \
                <input name="header_id[]" type="hidden" value="'+headcount+'"> \
                <a href="" class="rm-header fa fa-times-circle fa-lg" style="float:right; margin-right:5px; margin-top:5px"></a> \
                <label style="display:inline-block; float:right; margin-right:18px; font-weight: bold; color:#FFFFFF;" class="total">0.00</label> \
                <input name="header_subtotal[]" class="stotal" type="hidden" value="0.00"> </th> \
              <tbody class="subcontent tbody"></tbody>\
            </table>\
         </td>\
       </tr></div>');
$('tbody.content').prepend('\
\
\
小计:\
页眉“+编制+”\
\
\
\
0.00 \
\
\
\
\
');
api内部是

var dataid = $(that).closest('tr').find('.details_total').data('total_id');
subtotal2(dataid);
你必须做另一个小计函数

function subtotal2(dataid){ 
    var headertotal = 0;
    $('.details_total_'+dataid+'').each(function(){ 
        var price = $(this).val();
        headertotal += parseFloat(price);
        $('#total_'+dataid+'').text((headertotal).toFixed(2));
        $('#total_'+dataid+'').val((headertotal).toFixed(2));

    });
}

您可以共享
subtotal
函数以及视图函数subtotal(thisloc,eachloc,inloc){var headertotal=0;eachloc.each(function(){var price=$(this.val();headertotal+=parseFloat(price);$(thisloc).text((headertotal.toFixed(2));$(inloc.val((headertotal.toFixed)(2));}); }你能用HTML更新你的问题吗?我想每次调用小计时你都会覆盖这两个问题。为每个小计分配一个唯一的id,然后为每个
tr
定义一个与小计id匹配的数据属性,并在foreach for
tr
中获取该数据属性并将其作为id传递给小计功能。