對於我正在處理的項目,有幾個按鈕可打開不同的模式彈出窗口。每個窗口都有自己的複選框。如何將變量存儲到存儲到另一個數組(jQuery)的數組中
用戶選擇某些複選框然後關閉模式後,複選框信息將存儲在數組中並顯示在頁面上。
我的問題是,當用戶重新打開相同的模式彈出窗口時,我需要填寫這些相同的複選框。我發現了一個stackoverflow question which covers this here.
但是我的問題是,似乎我必須創建一個唯一的變量/數組,然後將該數組放入一個主數組,我不知道如何做到這一點。
// id of the button so I can use the name to open unique popups
// and create unique variable names
var roleId = '';
// The main Array to store all my button/checkbox lists Arrays into
var storedArray = [];
// The Array that stores the currently selected checkbox items.
var selectedArray = [];
// The function that is on all the buttons that bring up the checkbox modals
$('.role').click(function(){
// Saves a unique ID to be used to open up the appropriate popup
roleId = $(this).attr('tag');
// Here I try to create a Variable for a unique Array
storedArray.push('stored'+roleName);
// Selects the appropriate Modal popup
$('#modal-'+roleId).modal();
return false;
});
// Later the function that saves the checkbox items that are selected:
$('input:checked').each(function() {
selectedArray.push($(this).val());
});
// Where I try to store the checkbox data into the
// storedArray which is inside the slected Array
storedArray.push(selectedArray);
console.log('2 storedArray = '+storedArray);
你使用的是什麼模式庫? – 2013-04-04 19:15:19
簡單模態http://www.ericmmartin.com/projects/simplemodal/ :) – 2013-04-04 19:16:42