Javascript 复制多个Tds
我有一个3列6行的表。我想把其中的一些内容复制到一个新创建的列中,但是把它们插入中间。所以看起来是这样的: 有了这个办法:Javascript 复制多个Tds,javascript,jquery,html,Javascript,Jquery,Html,我有一个3列6行的表。我想把其中的一些内容复制到一个新创建的列中,但是把它们插入中间。所以看起来是这样的: 有了这个办法: $("table td:nth-child(2) [id$=2]").each(function(i) { var $newCell = $(this).wrap('<td></td').parent(); var $newRow = $("table td:nth-child(2) [id$=1]").eq(i).parents('tr');
$("table td:nth-child(2) [id$=2]").each(function(i) {
var $newCell = $(this).wrap('<td></td').parent();
var $newRow = $("table td:nth-child(2) [id$=1]").eq(i).parents('tr');
$(this).parents('tr').remove();
$newRow.append($newCell);
});
$("table td:nth-child(2) [id$=3]").each(function(i) {
var $newCell = $(this).wrap('<td></td').parent();
var $newRow = $("table td:nth-child(2) [id$=1]").eq(i).parents('tr');
$(this).parents('tr').remove();
$newRow.append($newCell);
});
$(“表td:n子(2)[id$=2])。每个(函数(i){
Valu$NealCys= $(this).Calp('< p>插入表中的任何东西,您可以做的是使用任何一个或。例如,我们希望在<代码> ABC < /代码>项之前插入我们的新单元格,而不是将其插入到结尾,您可以使用下面的代码在ABC 之前插入它(作为最后的<代码> TD/<代码>):
如果您想更具体一些,可以通过选择器中的文本来指定元素。因此,在本例中,您可以在包含文本的td
元素之前声明:
$newRow.find("td:contains('Abc')").before($newCell);
$newRow.find("td:contains('Abc')").before($newCell);