在JQuery中恢复多个分离的元素

我在表中有一个链接,当单击时,删除整个父tr 。 我正在使用detach()以便稍后根据事件恢复该项目。

通常,人们会将其存储为变量,然后稍后再调用它并稍后append() ,但是如果我需要恢复多行呢?

没有.=方法可以添加更多的变量吗?

JSFiddle = http://jsfiddle.net/nErDy/

为什么不使用数组呢?

 var deleted = []; //Allow people to delete rows $('a.delete').click(function() { deleted.push($(this).parent().parent().detach()); }); //Restore all $('a.restore').click(function() { $.each(deleted, function(i, v) { $('#teams').append(v); }); });​ 

http://jsfiddle.net/wirey00/nErDy/2/

你应该使用一个数组来存储所有dettached项目: http : //jsfiddle.net/nErDy/1/

其他人说的是,使用数组。 此外,将奇数行的css移动到实际的css中,因此它会尊重已删除的行。

 #teams tr:nth-child(even) td { background-color : #cecece }​ 

http://jsfiddle.net/44Qab/