查找单元格的 innerHTML

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function getCellContent(id) {
  6. var x = document.getElementById(id).rows[0].cells;
  7. document.getElementById("demo").innerHTML = x[0].innerHTML;
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <table id="myTable" style="border: 1px solid black">
  14. <tr>
  15. <td>cell 1</td>
  16. <td>cell 2</td>
  17. </tr>
  18. <tr>
  19. <td>cell 3</td>
  20. <td>cell 4</td>
  21. </tr>
  22. </table>
  23.  
  24. <p>
  25. <input type="button" onclick="getCellContent('myTable')" value="显示第一个单元格">
  26. </p>
  27.  
  28. <p id="demo"></p>
  29.  
  30. </body>
  31. </html>