Oldobj is an object, not a value
For example Var newobj=oldobj;
If you want to oldobj change the time does not affect the newobj;
You can write a function like this
Copy Code code as follows:
function Clone (myobj) {
if (typeof (MyObj)!= ' object ') return myobj;
if (myobj = null) return myobj;
var mynewobj = new Object ();
for (var i in myobj)
Mynewobj[i] = Clone (Myobj[i]);
return mynewobj;
}
And then call this
Newobj=clone (Oldobj)
After that, no matter how the value of the oldobj changes, it will not affect newobj
JavaScript Replication Objects
Grammar:
Oelement = object. CloneNode (Bclonechildren)
Parameters:
Bclonechildren: Options available. A Boolean value (Boolean). False | True
False: Default value. The ChildNodes collection of object is not included when the object is cloned. That is, all its child objects.
True: Contains the ChildNodes collection of object when cloning object. That is, all its child objects.
return value:
Oelement: Object (Element). Returns a reference to the new object after the clone.
Description
Clones the object in the document structure.
When the clone gets the ID of the cloned object, a collection is returned.
It is possible to use this method at run time. The document space may not be rendered before the object's closing tag is parsed.
Sample code:
Copy Code code as follows:
<script>
Function Rdl_fnclone () {
var oclonenode=olist.clone Node (TRUE);
Clonearea.appendchild (Oclonenode);
}
</script>
<table width=98%><tr><td>
<ul id=olist>
<li> 1th List Items
<li> 2nd <a href= "#" onclick= "return false;" > list Items </a>
<li style= "font-weight:bold;" > 3rd list Items
</ul>
</td><td id=clonearea>
</td></tr></table>
& L T;input Type=button value= "cloning" onclick= "Rdl_fnclone ();" >