drop EventListener不起作用

时间:2017-01-25 22:55:50

标签: javascript drag-and-drop draggable

当我拖动&删除文本,没有任何反应。但是当我将事件更改为" dragenter"或" dragleave"。我错过了什么吗?



function handleDragDrop(e) {
  console.log("Something droped");
  dropStatus.innerHTML = "Something droped";
}

var dropZone = document.getElementById("dropZone");
var dropStatus = document.getElementById("dropStatus");


dropZone.addEventListener("drop", handleDragDrop);

.drop-zone {
  width: 300px;
  padding: 20px;
  border: 2px dashed #000;
}

<div id="dropZone" class="drop-zone">Drop Zone!</div>
<div id="dropStatus"></div>

<div class="" draggable="true">DRAG ME</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

需要取消结束

function handleDragDrop(e) {
  console.log("Something droped");
  dropStatus.innerHTML = "Something droped";
}

var dropZone = document.getElementById("dropZone");
var dropStatus = document.getElementById("dropStatus");


dropZone.addEventListener("drop", handleDragDrop);
dropZone.addEventListener("dragover", function(e) {
  e.preventDefault();
  return false;
});
.drop-zone {
  width: 300px;
  padding: 20px;
  border: 2px dashed #000;
}
<div id="dropZone" class="drop-zone">Drop Zone!</div>
<div id="dropStatus"></div>

<div class="" draggable="true">DRAG ME</div>