我有一个类似这样的表:
<table>
<tr>
<td>some column|1</td>
<td id="abc|1">abc</td>
</tr>
<tr>
<td>another column|1</td>
<td id="def|1">def</td>
</tr>
<tr>
<td>some column|2</td>
<td id="abc|2">abc</td>
</tr>
<tr>
<td>another column|2</td>
<td id="def|2">def</td>
</tr>
</table>
我该如何将后缀为
|2
的tds
向右移动,以添加第三列? 同时,其余“空”td
,“some column|2”和“another column|2”应完全删除。
最终结果应如下所示:
以下是期望的代码:
<table>
<tr>
<td>some column|1</td>
<td id="abc|1">abc</td>
<td id="abc|2">abc</td>
</tr>
<tr>
<td>another column|1</td>
<td id="def|1">def</td>
<td id="def|2">def</td>
</tr>
</table>
这是我的做法,但并不可行:
$("table td:nth-child(2)[id$=2]").after("table td:nth-child(2)");
FIDDLE链接。