如何将列插入表格? [英] How do I insert column into table?
本文介绍了如何将列插入表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子,我想在第一行的给定值的左侧和右侧插入一列.您可以在此处查看其演示: http://jsfiddle.net/ismailp/vJvam/1/
I have a table and I'm trying to insert a column to the left and right of a given value on the first row. You can see a demo of it here: http://jsfiddle.net/ismailp/vJvam/1/
<table>
<tbody>
<tr>
<td>tag 1</td>
<td>tag 2</td>
<td>tag 3</td>
<td>tag 4</td>
<td>tag 5</td>
<td>tag 6</td>
</tr>
<tr>
<td>Some other value1</td>
<td>Some other value1</td>
<td>Some other value1</td>
<td>Some other value1</td>
<td>Some other value1</td>
<td>Some other value1</td>
</tr>
</tbody>
</table>
我已经将其用于表中的单行,但不适用于n + 1行. jQuery Guru可以在这里帮助我吗?
I've got it working for a single row in the table but not for n+1 rows. Could some jQuery Guru help me out here?
推荐答案
请参见: 演示
See this: DEMO
$("tbody tr").each( function() {
$(this).find("td:eq(" + cellBefore + ")").after("<td>" + spliceFirst + "</td>");
$(this).find("td:eq(" + cellAfter + ")").after("<td>" + spliceLast + "</td>");
});
简化: DEMO2
Simplified: DEMO2
$("tbody tr").each( function() {
$(this).find("td:eq(" + column + ")").after("<td>" + spliceFirst + "</td>").before("<td>" + spliceLast + "</td>");
});
这篇关于如何将列插入表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文