I have such a tab开发者_如何转开发le
<table><tr>
<td>some code</td>
<td>some code</td>
<td>some code</td>
</table>
How to modify it to
<table><tr>
<td>some code</td>
<tr><td>some code</td>
<tr><td>some code</td>
</table>
with Javascript?
Should work:
var table = document.getElementById("tableid");
var oldrow = table.getElementsByTagName("tr")[0];
var cells = oldrow.childNodes;
while (cells.length>0) {
var newrow = document.createElement("tr");
table.appendChild(newrow);
newrow.appendChild(cells[0]);
}
table.removeChild(oldrow);
精彩评论