jquery - 如何在 `drop` 事件后停止重定向?

标签 jquery html drag-and-drop

在 Firefox 中将文件放入 div 后,网页将被重定向到该文件。我试图在 drop 处理程序中使用 jQuery 的 e.preventDefault() 停止这种传播,但失败了。

参见 this demo ,将文件放入 #test 不会重定向网页,但放入 #test1 会,我想知道为什么。我是否应该始终将处理程序绑定(bind)到 dragenterdragoverdragleavedrop 以防止在 drop< 之后传播?

更新:

我在 html5doctor 上找到了一些提示:

To tell the browser we can drop in this element, all we have to do is cancel the dragover event. However, since IE behaves differently, we need to do the same thing for the dragenter event.

和 Mozilla claims :

A listener for the dragenter and dragover events are used to indicate valid drop targets, that is, places where dragged items may be dropped.

但我测试this demo在 firefox 上,#test 有效而 #test1 无效,Mozilla 似乎犯了一个错误,而 html5doctor 是正确的:Firefox 只需要 dragover使 drop 工作。

最佳答案

需要在 Google ChromeSafari 中取消 ondragover 事件以允许触发 ondrop 事件。

关于jquery - 如何在 `drop` 事件后停止重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8938319/

相关文章:

JQuery:单击链接时在鼠标位置显示隐藏的div

javascript - 获取链接的最后一个字符串

java - 如何以编程方式取消 Java/Swing 中的拖放操作?

JavaFX - 更改拖放描述

qt - Qt拖放中的热点是什么意思?

javascript - AngularJS 范围不绑定(bind) ng-repeat 中的数据

jquery - 如何在magento中触发fancybox html pop的点击

HTML 表单在输入文本中按 'Enter' 导致单击按钮

java - GWT 可以忽略某些代码行吗?

asp.net - 如何在 ASP.net 中使用 Web 表单中的 Web.config 设置控件的属性值