JavaScript 参考手册
tr insertCell() 方法
下面的例子在表格行中插入了一个单元
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <script> function displayResult() { var firstRow = document.getElementById("myTable").rows[0]; var x = firstRow.insertCell(-1); x.innerHTML = "New cell" } </script> </head> <body> <table id="myTable" border="1"> <tr> <td>First cell</td> <td>Second cell</td> <td>Third cell</td> </tr> </table> <br> <button type="button" onclick="displayResult()">插入单元格</button> </body> </html>
运行结果:
点击运行 »