[英]Change table structure using javascript
I am trying to switch a table structure from 我正在尝试从中切换表结构
<table>
<tr>
<td><div id=1"></div>
</td>
<td><div id=2"></div>
</td>
</tr>
</table>
to 至
<table>
<tr>
<td><div id=1"></div>
</td>
</tr>
<tr>
<td><div id=2"></div>
</td>
</tr>
</table>
and back to the original structure using JavaScript, would appreciate your suggestions. 并回到使用JavaScript的原始结构,将不胜感激您的建议。
I strongly suggest you remove the table and simply float the divs as described here 我强烈建议您删除表格,然后按照此处所述简单地将div浮动
div {
float: left;
}
I also suggest you do not use numeric IDs which is allowed in HTML5 but not very compatible and makes JavaScript accessing it potentially confusing 我还建议您不要使用HTML5中允许的数字ID,但数字ID不太兼容,并且JavaScript可能会混淆它
More efficient will be to use method appendTo
更有效的方法是使用方法appendTo
// append new line first
$('table').append('<tr></tr>');
// move td to the new tr
$('table tr td').last().appendTo($('table tr').last());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.