我有一个问题,我不知道如何解决:
我有张桌子:
\x{e76f}\x{e76f}A\x{e76f}B
\x{e76f}D\x{e76f}C
<table>
<tr>
<td>
A
</td>
<td>
B
</td>
</tr>
<tr>
<td>
C
</td>
<td>
D
</td>
</tr>
</table>现在,我需要在每个奇数td之后添加</tr><tr>。结果应该是一个列表:
\x{e76f}
(B)b
\x{e76f}
D__x
我已经试着用jQuery $("#table tr > td:nth-child(odd)").after("</tr><tr>");来完成这个任务,但是它不起作用。
有人能告诉我吗?
发布于 2013-04-07 10:25:01
试试这个:(http://jsfiddle.net/b5S3U/4/)
var cols = 1;
$('tr').each(function () {
var after = $(this);
while ($(this).children().length > cols) {
after = $('<tr>').insertAfter(after).append($('>:gt(' + (cols - 1) + '):lt(' + (cols) + ')', this));
}
})发布于 2013-04-07 10:31:23
试一试
$('table td:odd').each(function(i, v){
var $this = $(this);
var parent = $this.parent();
$this.detach().wrap('<tr></tr>').insertAfter(parent)
})演示:小提琴
https://stackoverflow.com/questions/15860851
复制相似问题