简体   繁体   中英

How to create a copy of a form with its DOM elements

如何创建一个包含所有表单元素的表单副本,以便可以操作副本并保持原始文件不变?

Using plain javascript cloneNode like this

var dupNode = node.cloneNode(deep);

Example

var p = document.getElementById("para1"),
var p_prime = p.cloneNode(deep); 
//If "deep" is set to true it will clone all the child nodes too,
//If set to false then only the node and not the children

Here is the documentation .

Hope that helps.

Use the jQuery clone object as such:

var cloned_object = $( ".hello" ).clone().

and to add it to the dom

cloned_object.appendTo( ".goodbye" );

Here is the reference:

http://api.jquery.com/clone/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM