HTML5拖放事件不起作用,除非拖放处理 [英] HTML5 drop event doesn't work unless dragover is handled

查看:161
本文介绍了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

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 event之前需要使用 e.preventDefault 来拖动事件。

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拖放事件不起作用,除非拖放处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆