开发者

modification of rows instead of columns in a table

开发者 https://www.devze.com 2023-01-31 03:01 出处:网络
I have such a tab开发者_如何转开发le <table><tr> <td>some code</td> <td>some code</td>

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

精彩评论

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