我得到了以下在控制台中出错的 js 代码,我不太确定自己做错了什么。基本上我正在尝试获取字段列表,以便我可以进行一些计算。
var LabourItems = {
rate: null,
hours: null,
total: null,
init: function(object) {
var rate = $(object).children('.rate').first();
var hours =$(object).children('.hours').first();
total = rate * hours;
updateTotal(object,total);
},
updateTotal: function(object, total) {
$(object).children('.total').first().attr('value', total)
}
}
//reactTochange for those inputs that you want to observe
$('.hours').live(function() {
var labourItems;
jQuery.each($('.labouritems'), function(key,value){
labourItems.push(LabourItems.init(value));
});
});
控制台错误:
Uncaught TypeError: Object function () {
var labourItems;
jQuery.each($('.labouritems'), function(key,value){
labourItems.push(LabourItems.init(value));
});
} has no method 'replace'