2

我在表格中有一个链接,单击该链接会删除整个 parent tr。我detach()用于稍后根据事件恢复该项目。

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

没有.=向变量添加更多内容的方法吗?

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

4

3 回答 3

8

Why not use an array?

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/

于 2012-08-21T16:11:49.363 回答
1

you should use an array to store all the dettached items: http://jsfiddle.net/nErDy/1/

于 2012-08-21T16:11:14.550 回答
1

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

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

http://jsfiddle.net/44Qab/

于 2012-08-21T16:17:19.887 回答