我得到了下面的代码,我有问题。除了第一个实例之外,我无法计算任何“Labouritems”实例的“总”数量,之后的每个实例我都无法计算。
var LabourItems = {
rate: null,
hours: null,
total: null,
init: function(object) {
this.rate = parseInt($(object).children('.rate').first().val(), 10);
// var rate = $(object).children('.rate').first();
this.hours =parseInt($(object).children('.hours').first().val(), 10);
this.total = this.rate * this.hours;
this.updateTotal(object);
},
updateTotal: function(object) {
$(object).children('.total').first().val(this.total || 0);
}
}
//reactTochange for those inputs that you want to observe
$('.labouritems input').on("keyup", function() {
$('.labouritems').each( function(key,value){
LabourItems.init(this);
});
});