<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <body> <table border="1" width="800" align="center" id="mytab"></table> </body> <script type="text/javascript"> //找表格对象 var mytab = document.getElementById('mytab'); //添加行 //创建也有添加作用 var row = mytab.insertRow(); //添加单元格 var td1 = row.insertCell(); td1.innerHTML = '这个是单元格1'; var td2 = row.insertCell(); td2.innerHTML = '这个是单元格2'; var td3 = row.insertCell(); td3.innerHTML = '这个是单元格3'; </script> </html>
点击 "运行实例" 按钮查看在线实例