本文介绍了如何克隆(和还原)DOM子树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想修改DOM子树并在一段时间后恢复它.如何保存一个子树副本到一边(以便与实际的子树一起玩)?之后如何恢复保存的副本?
I would like to modify a DOM subtree and restore it after a while. How can I save a sub-tree copy aside (to play with the actual subtree)? How can I restore the saved copy afterwards?
推荐答案
如果我没看错,那么我认为您要做的就是:
If I'm reading this right, then I think all you'd need to do is:
var DomTreeCopy = $('parentElementSelector').clone(true,true);
然后重新附加DomTreeCopy
(代替原始文件):
And then to re-attach the DomTreeCopy
(in place of the original):
$('parentElementSelector').replaceWith(DomTreeCopy);
或者将其添加到原始DOM之外:
Or to add it to the DOM in addition to the original:
$(DomTreeCopy).insertAfter($('parentElementSelector'));
参考文献:
这篇关于如何克隆(和还原)DOM子树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!