td 才是装text的控件,tr只是为了装td、th而存在的。
window.onload = function () {
var obj=document.body.innerHTML;
document.body.innerHTML = ""; var table = document.createElement("TABLE");
//table.setAttribute("id","tab");
var row = table.insertRow(table.rows.length);
row.className = "test";
var cell= row.insertCell(row.cells.length);
var text = document.createTextNode("textext");
cell.appendChild(text);
document.body.appendChild(table); alert(document.body.innerHTML);
}
window.onload = function () {
var obj=document.body.innerHTML;
document.body.innerHTML = ""; var table = document.createElement("TABLE");
//table.setAttribute("id","tab");
var row = table.insertRow(table.rows.length);
row.className = "test";
var cell= row.insertCell(row.cells.length);
var text = document.createTextNode("textext");
cell.appendChild(text);
document.body.appendChild(table); alert(document.body.innerHTML);
}
<script language=javascript>
window.onload = function () {
var obj=document.body.innerHTML;
document.body.innerHTML = "";
var table = document.createElement("table");
var tabody=document.createElement("tbody");
//table.setAttribute("id","tab");
var row = document.createElement("tr");
var cell=document.createElement("td")
row.className = "test";
var text = document.createTextNode("textext");
cell.appendChild(text);
row.appendChild(cell);
tabody.appendChild(row);
table.appendChild(tabody)
document.body.appendChild(table);
alert(document.body.innerHTML);
}
</script>