本文介绍了在JQuery中还原多个分离的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表中有一个链接,当单击该链接时,它会删除整个父级tr
.我正在使用detach()
以便稍后基于事件还原该项目.
I have a link inside of a table that, when clicked, removes the entire parent tr
. I am using detach()
for the purposes of restoring that item later based on an event.
通常,将其存储为变量,然后稍后调用它并在以后将其保存为append()
,但是如果我需要恢复多行怎么办?
Typically, one would store this as a variable, then recall it later and have it append()
later, but what if I need to restore multiple rows?
没有.=
方法可以向变量添加更多内容吗?
There is no .=
method to add more to a variable is there?
JSFiddle = http://jsfiddle.net/nErDy/
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/
这篇关于在JQuery中还原多个分离的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!