当前位置:网站首页>用cloneNode 克隆,解决id问题/方法 深复制和浅复制修改id的方法
用cloneNode 克隆,解决id问题/方法 深复制和浅复制修改id的方法
2022-06-12 11:59:00 【mustang(野马)】
cloneNode 使用函数方法解决深复制中id重复的问题
// var ul1=clones(ul,true);
// document.body.appendChild(ul1);
// 深复制修改id
// function clones(sourceElem,deep,target) {
// var elem;
// if(sourceElem){ //如果元素存在就克隆
// elem=sourceElem.cloneNode(deep); //deep是根据传入的参数定
// }else{
// elem=target; //递归回调函数中会用到这个
// }
// if(elem.id) elem.id+=1; //给有id的元素后面添加一个1
// for(var i=0;i<elem.children.length;i++){ //elem.children 是所有子元素,
// clones(null,false,elem.children[i]); //回调函数,也就是把这个行数再次执行一下,
//传入的参数是null也就是不再复制了,主要是修改元素的id
// }
// return elem;
// }
浅复制 修改ID
// var ul=document.querySelector("ul");
/* var ul1=clones(ul,false);
document.body.appendChild(ul1);
// 浅复制修改id
function clones(sourceElem,deep) {
var elem=sourceElem.cloneNode(deep);
if(elem.id) elem.id+=1;
return elem;
}*/
边栏推荐
猜你喜欢

First understand the onion model, analyze the implementation process of middleware, and analyze the source code of KOA Middleware

Video JS library uses custom components

Inter class and intra class relations in video classification -- regularization

JS to load and display Excel files

TinyMCE realizes automatic uploading of pasted pictures

A. Prefix range

无重复字符的最长字符串(LeetCode 3)

LeetCode 1037. 有效的回旋镖(向量叉乘)

Cookies and sessions

Cookie和Session
随机推荐
Basic concepts of machine learning
一个人必须不停地写作,才能不被茫茫人海淹没。
Multiplication instruction of arm instruction set
LeetCode_字符串_简单_344.反转字符串
7-5 complex quaternion operation
作物模型的区域模拟实现过程初探
Automatic generation of folder directory structure
单元测试用例框架--unittest
The second day of QML study
Load/store instruction addressing mode of arm instruction set (2)
【深度学习基础】反向传播法(1)
必杀技--使用FFmpeg命令快速精准剪切视频
Thirty one items that affect the weight of the store. Come and see if you've been hit
A. Prefix range
[foundation of deep learning] back propagation method (1)
Doris记录服务接口调用情况
Doris records service interface calls
promise的理解已经利用promise实现图片的预加载(顺序加载)
Blue Bridge Cup 2015 CA provincial competition (filling the pit)
MySQL - built in function