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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)