JS 操作 table
帮一个朋友写的,
<DIV id=right onclick="myClick();">
3333333333333
<table >
<tr><td>111</td><td>111</td></tr>
</table>
</DIV>
function myClick(){
var divID = document.getElementById("right");
var notesList = divID.childNodes;
for(var i = 0;i < notesList.length;i++){
if(notesList.item(i).nodeType == 1 && notesList.item(i).tagName=="TABLE" ) {
var tbTable= notesList.item(i);
var trT = tbTable.insertRow();
var nRows = tbTable.rows[0].cells.length;
for(var j = 0; j < nRows ; j++){
var tdT = document.createElement("TD");
tdT.innerText="我添加一行";
trT.appendChild(tdT);
}
}
}
}
3333333333333
<table >
<tr><td>111</td><td>111</td></tr>
</table>
</DIV>
function myClick(){
var divID = document.getElementById("right");
var notesList = divID.childNodes;
for(var i = 0;i < notesList.length;i++){
if(notesList.item(i).nodeType == 1 && notesList.item(i).tagName=="TABLE" ) {
var tbTable= notesList.item(i);
var trT = tbTable.insertRow();
var nRows = tbTable.rows[0].cells.length;
for(var j = 0; j < nRows ; j++){
var tdT = document.createElement("TD");
tdT.innerText="我添加一行";
trT.appendChild(tdT);
}
}
}
}