Javascript操作表格

1.在当前Row下插入一行

var currentRow=document.getElementById("row2011");

var newRow=currentRow.parentNode.insertRow(currentRow.rowIndex+1);

newRow.id="newRow2011";

var td0=newRow.insertCell();  td0.colSpan="2";  td0.innerHTML="岁月如梭";

var td1=newRow.insertCell();  td1.style.cssText="border:none;";  td1.innerHTML="光阴似箭";

 

2.删除当前Row

var currentRow=document.getElementById("row2011");

currentRow.parentNode.removeChild(currentRow);

 

3.访问当前Row的列

var currentRow=document.getElementById("row2011");

currentRow.cells(0).innerHTML="月月勤";

currentRow.cells(1).innerHTML="月月光";

currentRow.cells(2).innerHTML="月月忙";

currentRow.cells(3).innerHTML="月月空";

 

4.访问当前Table的行、列

var currentTable=document.getElementById("table2011");

currentTable.rows[0].cells(0).innerHTML="少年乐";

currentTable.rows[0].cells(1).innerHTML="白首悔";

currentTable.rows[1].cells(0).innerHTML="生死一线间";

currentTable.rows[1].cells(1).innerHTML="悔无重来时";

posted on 2011-11-28 09:44  林枫山  阅读(405)  评论(0编辑  收藏  举报