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

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

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)