且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果一个输入中有相同的类,则多个输入字段的 jquery 总和

更新时间:2023-10-05 20:57:16

你已经知道了,只需要为合适的选择器稍微调整你的 JQuery

You pretty much had it, just needed to adjust your JQuery a little bit for the appropriate selectors

更新小提琴:http://jsfiddle.net/5gsBV/7/

$(document).on("change", ".qty1", function() {
    var sum = 0;
    $(".qty1").each(function(){
        sum += +$(this).val();
    });
    $(".total").val(sum);
});