[英]file upload drag and drop issue
I've following HTML 我正在追踪HTML
<div class="upload_file" id="dropArea">
<form class="box row center" method="post" action="" enctype="multipart/form-data">
<div class="box_input column center">
<p class="title">BROWSE DATA FILE</p>
<span class="icon-upload_file"></span>
<input class="box_file" type="file" name="data" id="data" />
<label for="data" class="column center">
<p class="title">CHOOSE A FILE</p>
<p class="subtitle">or drag and drop it</p>
</label>
</div>
</form>
</div>
and associated javascript 和相关的javascript
let dropArea = document.getElementById('dropArea');
dropArea.addEventListener('dragover', function(event){
console.log(event.type); // works
}, false)
dropArea.addEventListener('drop', function(event){
event.preventDefault(); // opens the file in the browser
event.stopPropagation();
}, true);
I'm receiving drag 'over' event for sure, but the problem is with preventDefault, if i drag and drop an image or file, it opens up in the browser. 我肯定会收到拖放事件,但是问题出在preventDefault上,如果我拖放图像或文件,它将在浏览器中打开。 not sure what am I missing in here. 不知道我在这里想念什么。
Thanks, 谢谢,
You just need event.preventDefault();
您只需要event.preventDefault();
also in dragover
function 也有dragover
功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.