0
我創建了一個HTML表格並使用數據庫中的值填充。現在我想爲這個table創建編輯功能。我在表格的每一行添加了Edit按鈕。我需要知道相應的rowID按下相關的編輯按鈕。我使用java腳本來獲得該行的ID,但不幸的是我只得到第一行的細節。我想我需要把一些for循環。我需要此ID來傳遞另一個頁面,以便填充相應條目的值,並且用戶可以編輯條目並保存它們。我正在開發dotnet,但我不想使用任何gridview控件來做到這一點)。使用Java腳本從HTML表格獲取單元格數據按下編輯按鈕
如果您有任何示例代碼或解決方案,請寄給我。
<tr id= "listings">
<td style="width:16%; vertical-align:top; border-bottom: solid 1px black;" id = "ids">@@[email protected]@</td>
<td style="width:16%; vertical-align:top; border-bottom: solid 1px black; text-align:right;">@@[email protected]@</td>
<td style="width:2%; vertical-align:top; border-bottom: solid 1px black; text-align:right;"> </td>
<td style="width:16%; vertical-align:top; border-bottom: solid 1px black;">@@[email protected]@</td>
<td style="width:16%; vertical-align:top; border-bottom: solid 1px black;">@@[email protected]@</td>
<td style="width:16%; vertical-align:top; border-bottom: solid 1px black; text-align:right;">@@[email protected]@</td>
<td style="width:2%; vertical-align:top; border-bottom: solid 1px black; text-align:right;"> </td>
<td style="width:16%; vertical-align:top; border-bottom: solid 1px black; text-align:right;">
<button name = "editButton" type = "button" value = "Edit" onclick="test()">
Edit
</button>
</td>
</tr>
<script type="text/javascript">
function test() {
var elTableRow = document.getElementById("listings");
var elTableCells = elTableRow.getElementsByTagName("td");
alert(elTableCells[0].innerText);
}
</script>
有人請重播此... – BenoitParis 2010-09-10 10:14:09