1 回答
TA贡献1796条经验 获得超10个赞
您需要附加指令或函数才能在删除后获取数据。请检查这个例子。
超文本标记语言
<div id="div1" drop-on-me>
<img src="https://www.w3schools.com/html/img_w3slogo.gif" drag-me id="drag1" width="88" height="31">
</div>
<div id="div2" drop-on-me></div>
JS
angular
.module('myApp', []);
angular
.module('myApp')
.directive('dragMe', dragMe)
.directive('dropOnMe', dropOnMe);
dragMe.$inject = [];
function dragMe() {
var DDO = {
restrict: 'A',
link: function(scope, element, attrs) {
element.prop('draggable', true);
element.on('dragstart', function(event) {
event.dataTransfer.setData('text', event.target.id)
});
}
};
return DDO;
}
dropOnMe.$inject = [];
function dropOnMe() {
var DDO = {
restrict: 'A',
link: function(scope, element, attrs) {
element.on('dragover', function(event) {
event.preventDefault();
});
element.on('drop', function(event) {
event.preventDefault();
var data = event.dataTransfer.getData("text");
event.target.appendChild(document.getElementById(data));
});
}
};
return DDO;
}
CSS
#div1,
#div2 {
float: left;
width: 100px;
height: 35px;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报