查找单元格的 innerHTML
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function getCellContent(id) {
- var x = document.getElementById(id).rows[0].cells;
- document.getElementById("demo").innerHTML = x[0].innerHTML;
- }
- </script>
- </head>
- <body>
- <table id="myTable" style="border: 1px solid black">
- <tr>
- <td>cell 1</td>
- <td>cell 2</td>
- </tr>
- <tr>
- <td>cell 3</td>
- <td>cell 4</td>
- </tr>
- </table>
- <p>
- <input type="button" onclick="getCellContent('myTable')" value="显示第一个单元格">
- </p>
- <p id="demo"></p>
- </body>
- </html>