[英]Drag and drop a clone in javascript
I am making a drag and drop section, on the top I have the value fields which can be mapped to the Key fields. 我正在创建一个拖放部分,在顶部,我具有可以映射到键字段的值字段。
I am using HTML5 drag and drop for this. 我为此使用HTML5拖放。 What I want is, it should make a clone of the div and then drag and drop that.
我想要的是,它应该复制div,然后将其拖放。 I don't want the original Value chip to disappear from the top bar.
我不希望原始的Value芯片从顶部栏消失。
public drop(ev) {
ev.preventDefault();
if (ev.target.hasChildNodes()) {
return;
}
const data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
public drag(ev) {
this._logger.warn("Inside drag()");
ev.dataTransfer.setData("text", ev.target.id);
}
public allowDrop(ev) {
ev.preventDefault();
if (ev.target.hasChildNodes()) {
return;
}
}
您可以使用cloneNode()克隆原始div,然后对其进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.