开发者

modification of rows instead of columns in a table

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜