如何用JavaScript操作table中tr中td的值?
如何用JavaScript操作table中tr中td的值?
如何用JavaScript操作table中tr中td的值?
如何用JavaScript操作table中tr中td的值?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
5条回答 默认 最新
tsinggao 2015-08-18 01:57关注<html> <head> <title> 修改td中的值 </title> </head> <body> <table id="myTable" width="400px" border="1px solid #CCC"> <tr> <td height="50px" width="25%"> 1,1</td> <td height="50px" width="25%"> 1,2</td> <td height="50px" width="25%"> 1,3</td> <td height="50px" width="25%"> 1,4</td> </tr> <tr> <td height="50px" width="25%"> 2,1</td> <td height="50px" width="25%"> 2,2</td> <td height="50px" width="25%"> 2,3</td> <td height="50px" width="25%"> 2,4</td> </tr> <tr> <td height="50px" width="25%"> 3,1</td> <td height="50px" width="25%"> 3,2</td> <td height="50px" width="25%"> 3,3</td> <td height="50px" width="25%"> 3,4</td> </tr> </table> <br> <hr> <br> <input type="text" size="20" id="inputText"> <input type="button" value="修改(3,3)td中的值" onclick="updateValue('inputText',2,2);" </body> <script> function updateValue(textId,row,col){ table = document.getElementById('myTable'); table.rows[row].cells[col].firstChild.nodeValue = document.getElementById(textId).value; } </script> </html>本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报