2010-09-10 68 views
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;">&nbsp;&nbsp;</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;">&nbsp;</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> 
+0

有人请重播此... – BenoitParis 2010-09-10 10:14:09

回答

0

您的代码是不工作的原因是什么测试方法的作用是:
- 获取第一个元素ID为上市
- 获取里面的房源
标签名TD的所有元素 - 显示首个TD的的innerText

你想要做的是:
- Click事件中,获得该按钮被点击
对于该行 - 显示行的数据

相关问题