当前位置:网站首页>Clone with cloneNode to solve the id problem / methods deep copy and shallow copy to modify the ID
Clone with cloneNode to solve the id problem / methods deep copy and shallow copy to modify the ID
2022-06-12 12:04:00 【Mustang (Mustang)】
cloneNode Use the function method to solve the problem of deep replication id Repetitive questions
// var ul1=clones(ul,true);
// document.body.appendChild(ul1);
// Deep copy modification id
// function clones(sourceElem,deep,target) {
// var elem;
// if(sourceElem){ // If the element exists, clone it
// elem=sourceElem.cloneNode(deep); //deep It is determined according to the passed in parameters
// }else{
// elem=target; // This is used in recursive callback functions
// }
// if(elem.id) elem.id+=1; // Here you are id Add a... After the element of 1
// for(var i=0;i<elem.children.length;i++){ //elem.children Is all child elements ,
// clones(null,false,elem.children[i]); // Callback function , That is, execute this row number again ,
// The parameter passed in is null That is, no more copying , Mainly to modify the elements id
// }
// return elem;
// }
A shallow copy modify ID
// var ul=document.querySelector("ul");
/* var ul1=clones(ul,false);
document.body.appendChild(ul1);
// Shallow copy modification id
function clones(sourceElem,deep) {
var elem=sourceElem.cloneNode(deep);
if(elem.id) elem.id+=1;
return elem;
}*/
边栏推荐
- LeetCode 1037. 有效的回旋镖(向量叉乘)
- 导航中,添加边框影响布局的解决方法
- Doris records service interface calls
- 5g NR protocol learning -- ts38.211 downlink channel
- Ros- resolve error "tf2\u buffer\was not declared in this scope"
- LeetCode 1037. Effective boomerang (vector cross product)
- Create servlet project
- The first thing with a server
- ARM processor mode and register
- ARM指令集之数据处理类指令
猜你喜欢
随机推荐
Create servlet project
Google Earth Engine(GEE)——Kmeans聚类快速进行土地分类(双for循环快速调参)
Pseudo instruction of arm instruction set
ARM指令集之Load/Store指令寻址方式(二)
【Leetcode】221. Largest Square
for in 与Object.keys()的区别
【深度学习基础】反向传播法(1)
The second regular match is inconsistent with the first one, and the match in the regular loop is invalid
转载--win10打开任务管理器就蓝屏的问题
ARM指令集之批量Load/Store指令
JS to load and display Excel files
第六章 数据类型(五)
Design of TTable
QT based travel query and simulation system
LeetCode_ Binary search_ Medium_ 162. looking for peaks
Node crawler puppeter usage
5G NR協議學習--TS38.211下行通道
Thirty one items that affect the weight of the store. Come and see if you've been hit
無重複字符的最長字符串(LeetCode 3)
First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware









