點擊修改,在修改界面的文本框中,出現的就是這行記錄的值。
初始界面:
修改界面:
JS代碼:
/*獲取表格中某行的學生信息*/
$("#body").on('click','.update',function () {
// const no=$(this).closest("tr").find("td").eq(0).text();
$("#alterSno").val($(this).closest("tr").find("td").eq(0).text());
$("#alterSname").val($(this).closest("tr").find("td").eq(1).text());
$("#alterSsex").val($(this).closest("tr").find("td").eq(2).text());
// delete_Stu(no);
})
通過$(this).closest(“tr”).find(“td”).eq(0).text()可以獲取所要修改的記錄的各列的值,this是指修改的那行記錄。
$(this).closest(“tr”):定位距離這行記錄最近的“tr”標籤(即這行記錄在哪個tr標籤內)
$(this).closest(“tr”).find(“td”).eq(0).text():獲取標籤內的第一個標籤內的值