除非处理了拖动,否则 HTML5 放置事件不起作用

HTML5 drop event doesn#39;t work unless dragover is handled(除非处理了拖动,否则 HTML5 放置事件不起作用)
本文介绍了除非处理了拖动,否则 HTML5 放置事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在监听 drop 事件并执行 e.preventDefault() 但它试图打开删除的文件.直到昨天它工作正常.但就在今天,它不知什么原因坏了.我做了一个 JsFiddle#bwquR/10 来反映相同的.

I am listening to the drop event and doing e.preventDefault() But its trying to open the dropped file. It was working fine till yesterday. But just today It broke for some unknown reason. I made a JsFiddle#bwquR/10 to reflect the Same.

看起来如果你不采取 dragover 事件 drop 是无法处理的.即使在小提琴中如果您评论 dragover 它将无法正常工作.
在实际工作中我错过了 dragover 的拼写但它仍然是一个问题 drop will not work without dragover

It looks like if you don't take the dragover event drop cannot be handled. even in the the fiddle If you comment the dragover It will not work.
In the actual work I missed the spelling of dragover But its still a question drop will not work without dragover

小提琴实际上在工作,但身体太小了(只有文本 DROP 那里).它仅在 DROP 文本不在整个正文上的那个小区域上发生 drop 事件.所以我认为它不起作用.很抱歉造成混乱.

The fiddle was actually working but s the body was so small (only text DROP there). It was taking drop event only on that small area where DROP text lies not on the entire body. So I thought It was not working. Sorry for the confusion.

推荐答案

我猜是因为没有dragOver事件处理程序,使用了dragOver事件的默认事件处理程序,因此之后没有触发drop事件.在放置事件之前需要 e.preventDefault 用于 dragOver 事件.

I guess it is because that without dragOver event handler, default event handler of dragOver event is used, thus, no drop event is triggered after that. There is a need with e.preventDefault for dragOver event before drop event.

这篇关于除非处理了拖动,否则 HTML5 放置事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Drag amp; Drop with Protractor by Repeater(拖动amp;通过中继器使用量角器掉落)
Getting the position of the element in a list when it#39;s drag/dropped (ui.sortable)(拖放时获取元素在列表中的位置(ui.sortable))
Detecting HTML5 Drag And Drop support in javascript(在 javascript 中检测 HTML5 拖放支持)
How to use jQuery#39;s drop event to upload files dragged from the desktop?(如何使用 jQuery 的 drop 事件上传从桌面拖动的文件?)
Drop image into contenteditable in Chrome to the cursor(将图像拖放到 Chrome 中的 contenteditable 到光标处)
HTML5: dragover(), drop(): how get current x,y coordinates?(HTML5: dragover(), drop(): 如何获取当前 x,y 坐标?)