<script type="text/javascript"> function tableDom(){ var table = document.createElement("table"); table.border = "1" document.body.appendChild(table); var tbody = document.createElement('tbody'); table.appendChild(tbody); var tr = document.createElement('tr'); tbody.appendChild(tr) var td = document.createElement('td'); td.appendChild(document.createTextNode("td1")); tr.appendChild(td); var td = document.createElement('td'); td.appendChild(document.createTextNode("td2")); tr.appendChild(td); var td = document.createElement('td'); td.appendChild(document.createTextNode("td3")); tr.appendChild(td); var td = document.createElement('td'); td.appendChild(document.createTextNode("td4")); tr.appendChild(td); } tableDom(); </script> <script type="text/javascript"> function tableHtml(){ var table = document.createElement("table"); table.border = "1" document.body.appendChild(table); var tbody = document.createElement('tbody'); table.appendChild(tbody); //创建第一行 tbody.insertRow(0); tbody.rows[0].insertCell(0); tbody.rows[0].cells[0].appendChild(document.createTextNode("td1")); tbody.rows[0].insertCell(1); tbody.rows[0].cells[1].appendChild(document.createTextNode("td2")); tbody.rows[0].insertCell(2); tbody.rows[0].cells[2].appendChild(document.createTextNode("td3")); tbody.rows[0].insertCell(3); tbody.rows[0].cells[3].appendChild(document.createTextNode("td4")); } tableHtml(); </script> <div id="div1"></div> <script type="text/javascript"> function tableinnerHTML(){ var table =[]; table.push("<table border='1'><tbody><tr>"); for(var i = 1; i<=4;i++){ table.push("<td>"); table.push("td"+i) table.push("<\/td>"); } table.push("<\/tr><\/tbody><\/table>"); document.getElementById("div1").innerHTML = table.join(""); } tableinnerHTML(); </script> <script type="text/javascript"> function tableCloneDom(){ var table,tbody,tr,td; otr = document.createElement("tr"); otd = document.createElement("td"); tbody = document.createElement("tbody"); table = document.createElement("table"); table.border = "1"; tr=otr.cloneNode(false); for(var i=1;i<=4;i++){ td=otd.cloneNode(false); td.appendChild(document.createTextNode('td'+i)); tr.appendChild(td); tbody.appendChild(tr); } table.appendChild(tbody); document.body.appendChild(table); } tableCloneDom(); </script>