Javascript Jquery函数仅对第一行有效,即使使用$(document).on()

Javascript Jquery函数仅对第一行有效,即使使用$(document).on(),javascript,php,jquery,html,invoice,Javascript,Php,Jquery,Html,Invoice,我学习了一个使用PHP jquery mysql和bootstrap的发票系统教程。我一个字符接一个字符地跟踪代码,但特定类的$(document).on()函数不起作用。然而,在教程视频中,它似乎起了作用主要问题是$(document).on()函数调用只对表中的第一行有效,对其余行无效。 提前感谢您的帮助 HTML部分: <td><input type="text" name="order_item_quantity[]" id="order_item_quantity'+

我学习了一个使用PHP jquery mysql和bootstrap的发票系统教程。我一个字符接一个字符地跟踪代码,但特定类的$(document).on()函数不起作用。然而,在教程视频中,它似乎起了作用主要问题是$(document).on()函数调用只对表中的第一行有效,对其余行无效。

提前感谢您的帮助

HTML部分:

<td><input type="text" name="order_item_quantity[]" id="order_item_quantity'+count+'" data-srno="'+count+'" class="form-control input-sm number_only order_item_quantity"></td>

<td><input type="text" name="order_item_price[]" id="order_item_price'+id+'" data-srno="'+id+'" class="form-control input-sm number_only order_item_price"></td>

<td><input type="text" name="order_item_actual_amount[]" id="order_item_actual_amount'+count+'" data-srno="'+count+'" class="form-control input-sm order_item_actual_amount" readonly /></td>

如果以前有人问过这个问题,我很抱歉,但我确实在这里检查了类似的问题,并尝试了建议的解决方案,但它们似乎都不起作用。提前感谢您的回答。

您只需替换此代码即可解决此问题

function cal_final_total() {
    var final_item_total = 0;
    $('.order_item_quantity').each(function(){
        parent = $(this).closest('tr');
        qty = +parent.find('.order_item_quantity').val();
        price = +parent.find('.order_item_price').val();
        actualAmount = qty*price;
        final_item_total += final_item_total;
        parent.find('.order_item_actual_amount').val(actualAmount);
    });
}

确保您的输入字段位于单独的tr标记中

,正如您在这里介绍的那样,只有当您移出第二列时,它才会起作用,因为我省略了整个代码的某些部分,第二列是唯一一个带有class
order\u item\u price
的列。。但是谢谢你的回复。
                    $(document).on('blur', '.order_item_price', function(){
                        cal_final_total(count);
                    });
function cal_final_total() {
    var final_item_total = 0;
    $('.order_item_quantity').each(function(){
        parent = $(this).closest('tr');
        qty = +parent.find('.order_item_quantity').val();
        price = +parent.find('.order_item_price').val();
        actualAmount = qty*price;
        final_item_total += final_item_total;
        parent.find('.order_item_actual_amount').val(actualAmount);
    });
}