Javascript 当 ondrop 被触发时 event.dataTransfer.files 是空的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11573710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
event.dataTransfer.files is empty when ondrop is fired?
提问by nkcmr
Okay, I have an element set up to receive a file-drop event, but when I look in event.dataTransfer
it is blank. I haven't gotten around to learning the drag-n-drop HTML5 API just yet and am still a little foggy on it. I'm working on it at my site. If you wouldn't mind poking around my code and seeing what's going on, it would be highly appreciated. The entire event
object is being logged.
好的,我设置了一个元素来接收文件放置事件,但是当我查看event.dataTransfer
它时它是空白的。我还没有开始学习拖放 HTML5 API,并且对它仍然有点模糊。我正在我的网站上处理它。如果您不介意浏览我的代码并了解发生了什么,我将不胜感激。event
正在记录整个对象。
回答by Esailija
It's working fine, it's just a bug with the console.
它工作正常,只是控制台的一个错误。
function onDrop(event) {
event.preventDefault();
console.log(event.dataTransfer.files[0]);
}
回答by WFW
Also take a look at this bug/behavior: HTML5 drop event doesn't work unless dragover is handled
还要看看这个错误/行为:HTML5 drop 事件不起作用,除非处理dragover
Basically, you need to handle hover/drag and specify a dropEffect
基本上,您需要处理悬停/拖动并指定 dropEffect
回答by Andrew
I found what I needed in:
我找到了我需要的东西:
e.originalEvent.dataTransfer