我在移動應用程序,我想用複選框的值填充數組。jquery如何填充數組
我的代碼是
if (row.flatdescription == flatdescription) {
if (row.receiptno == 0){
items.push('<input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '" previous="' + row.pastpayments + '" barcode="' + row.barcode + '" todayp="' + row.todaypayments + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></br>');
}
allbarcode[i] = row.barcode;
previouspayments1 = previouspayments1 + row.pastpayments;
previouspayments = previouspayments1.toFixed(2);
sofeilon1 = sofeilon1 + row.amount;
sofeilon = sofeilon1.toFixed(2);
total1 = total1 + row.amount - row.pastpayments;
total = total1.toFixed(2);
}
和我的陣列碼
function barcodeTotal() {
barcode = [];
barcodeamount = [];
barcodeprevious = [];
$("input:checked").each(function(i) {
barcode[i] = $(this).attr("barcode");
barcodeamount[i] = $(this).attr("value");
barcodeprevious[i] = $(this).attr("previous");
});
}
我的目標是填補條形碼陣列這樣
barcode [barcode: barcode, amount: value, previous: previous, ....
我會感謝你的答案
我使所建議的修改,但我收到警報[對象的對象],[對象的對象] function barcodeTotal(){ \t \t \t \t var self = this; \t \t \t \t var barcodes = []; \t \t \t \t $( 「輸入:勾選」)。每個(函數(I,項目){ \t \t \t \t \t barcodes.push({ \t \t \t \t \t \t條碼:$(個體經營).attr( 「條形碼」), \t \t \t \t \t \t金額:$(個體經營).attr( 「值」), \t \t \t \t \t \t前一個:$(self).attr(「previous」) \t \t \t \t \t}); \t \t \t \t \t // barcode [i] = $(this).attr(「barcode」); \t \t \t \t \t // barcodeamount [i] = $(this).attr(「value」); \t \t \t \t \t // barcodeprevious [i] = $(this).attr(「previous」); \t \t \t}); 提醒(條形碼); \t \t \t} – kosbou 2012-02-11 08:02:00