触发 ondrop 时 event.dataTransfer.files 为空?

2022-01-11 00:00:00 drag-and-drop javascript html

好的,我设置了一个元素来接收文件放置事件,但是当我查看 event.dataTransfer 时,它是空白的.我还没有开始学习拖放式 HTML5 API,而且对它还有点迷糊.我正在我的网站 上处理它.如果您不介意浏览我的代码并查看发生了什么,我们将不胜感激.正在记录整个 event 对象.

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.

推荐答案

它工作正常,只是控制台的一个错误.

It's working fine, it's just a bug with the console.

function onDrop(event) {
    event.preventDefault();
    console.log(event.dataTransfer.files[0]);
}

相关文章