通過點擊選中的checkbox獲取該行td的值
並將對象封裝,返回JSON對象
// 彈出層保存事件 function addMarketClues () { var marketCluesList = []; // table 中checkbox獲取選中行的所有列的數據 var check = $("table input[type=checkbox]:checked");//在table中找input下類型為checkbox屬性為選中狀態的數據 check.each(function () { var marketClues = {}; var row = $(this).parent("td").parent("tr");//獲取選中行 marketClues.studentName = row.find("[name='repeatStudentName']").html(); //獲取td中name='repeatStudentName'的值 marketClues.tel = row.find("[name='repeatTel']").html(); marketClues.grade = row.find("[name='repeatGrade']").html(); marketClues.age = row.find("[name='repeatAge']").html(); marketClues.school = row.find("[name='repeatSchool']").html(); marketClues.entryName = row.find("[name='repeatEntryName']").html(); marketClues.intentionCampus = row.find("[name='repeatIntentionCampus']").html(); marketCluesList.push(marketClues) }); console.log(JSON.stringify(marketCluesList)); }
獲取選中的checkbox的值
//獲取選中的checkbox的值 var ids = []; $("input[name='ids']:checked").each(function(i){ ids.push($(this).val()) $("body").append("<p>"+$(this).val()+"</p>") })