DOM表格操作

来源:互联网 发布:java反序列化漏洞原理 编辑:程序博客网 时间:2024/05/16 18:48
创建一个表var table=document.createElement("table");table.border=1;table.width="100%";创建tbodyvar tbody=document.createElement("tbody");table.appendChild(tbody);创建第一行tbody.insertRow(0);tbody.rows[0].insertCell(0);tbody.rows[0].cells[0].appendChild(document.createTextNode("cell 1,1"));tbody.rows[0].insertCell(1);tbody.rows[0].cells[1].appendChild(document.createTextNode("cell 2,1"));创建第二行tbody.insertRow(1);tbody.rows[1].insertCell(0);tbody.rows[1].cells[0].appendChild(document.createTextNode("cell 1,2"));tbody.rows[1].insertCell(1);tbody.rows[1].cells[1].appendChild(document.createTextNode("cell 2,2"));将表格添加到文档主体中document.body.appendChild(table);

0 0