window.onload = function(){
var table = document.createElement('table');
table.border = 1;
table.width = '100%';
var tbody = document.createElement('tbody');
table.appendChild(tbody);
//主角登场了 insertRow; 作用是向指定位置插入一行 rows返回表格的所有行 cells返回表格所有单元格 insertCell与insertRow一样 只不过它是向指定位置插入一个单元格。 tbody.insertRow(0);//创建一行
tbody.rows[0].insertCell(0);//创建第一行 第一个单元格
tbody.rows[0].cells[0].appendChild(document.createTextNode('1,1'));//给单元格添加文本
tbody.rows[0].insertCell(1);//创建第一行 第二个单元格
tbody.rows[0].cells[1].appendChild(document.createTextNode('1,2'));
tbody.insertRow(1);
tbody.rows[1].insertCell(0);//创建第二行 第一个单元格
tbody.rows[1].cells[0].appendChild(document.createTextNode('2,1'));
tbody.rows[1].insertCell(1);//创建创建第二行 第二个单元格
tbody.rows[1].cells[1].appendChild(document.createTextNode('2,2'));
tbody.rows[1].insertCell(2);
tbody.rows[1].cells[2].appendChild(document.createTextNode('2,3'));
document.body.appendChild(table);
}
有不对的地方 请大家指正