$("#t_Content tr").each(function () { // #t_Content tr 在Id為t_Content元素下查找tr元素,t_Content為tbody
var arrayKeys = new Array(); // 聲明一個(gè)Array數(shù)組用來(lái)存儲(chǔ)keys
var arrayValues = new Array(); // 聲明一個(gè)Array數(shù)組用來(lái)存儲(chǔ)Values
var saveDate = { // 這里聲明一個(gè)對(duì)象,注意值類(lèi)型與引用類(lèi)型的區(qū)別,否則會(huì)導(dǎo)致這個(gè)Array中的數(shù)據(jù)均為最后的值
InputKeys: [], // 存儲(chǔ)keys屬性
InputValues: [] // 存儲(chǔ)Values屬性
};
var t = $(this); // 注:需要把本次的tr保存到一個(gè)變量中,否則下次$(this)調(diào)用是this已經(jīng)改變了會(huì)導(dǎo)致錯(cuò)誤
t.find(":input[type='text']").each(function (index, element) { // 在tr下find標(biāo)簽是input并“type='text'”元素,分別保存id與values
arrayKeys.push($(this).attr("id"));
arrayValues.push($(this).val());
});
if (arrayKeys.length > 0) { // 如果數(shù)組中有數(shù)據(jù)則保存到arrayList中直接push進(jìn)去就好
saveDate.InputKeys = arrayKeys;
saveDate.InputValues = arrayValues;
arrayList.push(saveDate);
}