改变表格单元格的内容

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function changeContent(id, row, cell, content) {
  6. var x = document.getElementById(id).rows[row].cells;
  7. x[cell].innerHTML = content;
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <table id="myTable" border="1">
  14. <tr>
  15. <td>Row1 cell1</td>
  16. <td>Row1 cell2</td>
  17. </tr>
  18. <tr>
  19. <td>Row2 cell1</td>
  20. <td>Row2 cell2</td>
  21. </tr>
  22. <tr>
  23. <td>Row3 cell1</td>
  24. <td>Row3 cell2</td>
  25. </tr>
  26. </table>
  27.  
  28. <p>
  29. <input type="button" onclick="changeContent('myTable', 0, 0, 'Hello')" value="更改内容">
  30. </p>
  31.  
  32. </body>
  33. </html>