我有下面的代码,我无法在每一行元素中填充总字段。
所以动态插入的每个字段都将具有相同的字段,我只需要计算该行中的字段。
这是它的 jsfiddle http://jsfiddle.net/glennmartin/3TnyR/
var LabourItems = {
rate: null,
hours: null,
total: null,
init: function(object) {
var rate = parseInt($(object).children('.rate').val(), 10);
// var rate = $(object).children('.rate').first();
var hours =parseInt($(object).children('.hours').val(), 10);
this.total = Number(rate.val()) * Number(hours.val());
this.updateTotal(object);
},
updateTotal: function(object) {
$(object).children('.total').first().attr('value', this.total)
}
}
//reactTochange for those inputs that you want to observe
$('.hours').on("click", function() {
jQuery.each($('.labouritems'), function(key,value){
LabourItems.init(value);
});
});