操作后如何重置DOM? [英] How to reset DOM after manipulation?
问题描述
我的页面包含一些我使用jQuery构建的小向导。
My page contains some small wizard which I built using jQuery.
我想让用户重启/重置向导并从初级启动它。
I would like to offer the user to restart/reset the wizard and start it from the beginning level.
无论如何都可以不刷新页面吗?
There is anyway to do it without refreshing the page?
推荐答案
实现这一目标的一种方法是 clone()向导的元素树处于初始状态,将其存储在全局变量或文档的数据中:
One way to achieve this would be to clone() the wizard's element tree in its initial state and store it in a global variable or in the document's data:
$(document).data("initialWizard", $("#yourWizard").clone(true));
(请注意,将 true
传递给 clone()
还克隆了元素数据和事件处理程序,在你的情况下可能会很方便。)
(Note that passing true
to clone()
also clones element data and event handlers, which might prove handy in your case.)
然后,当你想要将向导恢复到原始状态,你可以这样做:
Then, when you want to restore the wizard to its original state, you can do:
$(document).data("initialWizard").replaceAll("#yourWizard");
这篇关于操作后如何重置DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!