我有下面的代码,用于计算插入的每个实例(行)的两个字段。
目前,它填充所有“总计”字段,而不仅仅是对应行的字段。
还将“NaN”插入到所有总字段中。
var LabourItems = {
rate: null,
hours: null,
total: null,
init: function(object) {
var rate = $(object).children('.rate').first();
var hours =$(object).children('.hours').first();
this.total = Number(rate) * Number(hours);
this.updateTotal(object);
},
updateTotal: function(object) {
$(object).children('.total').first().attr('value', this.total)
}
}
//reactTochange for those inputs that you want to observe
$('.hours').live("click", function() {
jQuery.each($('.labouritems'), function(key,value){
LabourItems.init(value);
});
});