表格對象的獲取
var oT = document.getElementById("tb");
//獲取head
console.log(oT.tHead);
console.log(typeof oT.tHead);
//獲取body
console.log(oT.tBodies);//[tbody]
console.log(typeof oT.tBodies);
//獲取foot
console.log(oT.tFoot);
//獲取行[tr,tr...]
console.log(oT.rows);
//修改第三行的顏色
oT.rows[2].style.background="blue";
//獲取單元格(不能直接通過表格對象獲取,通過行獲取單元格)
// console.log(oT.cells);//undefined
var rows = oT.rows;//[tr,tr...]
var cells=rows[rows.length-1].cells;
console.log(cells);//[td,td,td,td]
cells[cells.length-1].style.background="red";
表格元素的修改
var oT = document.getElementById("tb");
//插入行
//參數:下標
var newRow=oT.insertRow(1);
// console.log(newRow);
// newRow.innerHTML="new insertRow";
//在行中插入單元格
var newTd=newRow.insertCell(0);
newTd.innerHTML = "小明";
// console.log(newTd);
newRow.insertCell(1).innerHTML="18";
newRow.insertCell(2).innerHTML="男";
newRow.insertCell(3).innerHTML="工程師";
