How to modify the id value of the child element under the id after the id object is cloned in js
Untitled Document
Image 1 address:
Image 1 link:
Add an image
Delete an image
Generate code
Script
Var zhs = 0;
Var $ = function (cs ){
Return document. getElementById (cs)
};
Function tjs (){
Var sourceNode = $ ("tps _" + zhs );
Var clonedNode = sourceNode. cloneNode (true); // clone a node
Zhs = zhs + 1;
Var vbn = "tps _" + zhs
ClonedNode. setAttribute ("id", vbn );
SourceNode. parentNode. appendChild (clonedNode); // Insert a cloned node to the parent node.
}
Script
The above is the code that I wrote that only changed the parent id. the code that does not write can also modify the child element id value. I may not be clear about it. the code below is to do the following:
Untitled Document
Image 1 address:
Image 1 link:
Image 2 address:
Image 2 link:
Image 3 address:
Image 3 link:
Add an image
Delete an image
Generate code
Reply to discussion (solution)
Complete as function
function as() { alert($('lbys').innerHTML);}No error found after running
The id of p increments as expected.
On the 3q2 floor, I picked my code and forgot to pick the as () container. you may not understand what I mean.
I didn't understand what you mean.
Because you have not modified the input id code
I want to modify the input id.
Can I write
Can't write? Then you can make it clear.
Actually, you write it.
Function tjs () {var sourceNode =$ ("tps _" + zhs); var clonedNode = sourceNode. cloneNode (true); // clone node zhs = zhs + 1; var vbn = "tps _" + zhs clonedNode. setAttribute ("id", vbn); var o = clonedNode. childNodes; for (I = 0; I
3q: I only learned as2. now I want to learn js, so I don't know about js. thanks to my reply, I also came up with a stupid method.
It is wise to modify html content without the powerful code.
Function tjs (){
Var sourceNode = $ ("tps _" + zhs );
Var clonedNode = sourceNode. cloneNode (true); // clone a node
Zhs = zhs + 1;
Var vbn = "tps _" + zhs
ClonedNode. setAttribute ("id", vbn );
SourceNode. parentNode. appendChild (clonedNode); // Insert a cloned node to the parent node.
$ (Vbn). innerHTML = "image" + zhs + "address:"+" Image "+ zhs +" link:"
}