在 Firefox 中将文件放入 div
后,网页将被重定向到该文件。我试图在 drop
处理程序中使用 jQuery 的 e.preventDefault()
停止这种传播,但失败了。
参见 this demo ,将文件放入 #test
不会重定向网页,但放入 #test1
会,我想知道为什么。我是否应该始终将处理程序绑定(bind)到 dragenter
、dragover
、dragleave
和 drop
以防止在 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
anddragover
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 Chrome 和 Safari 中取消 ondragover
事件以允许触发 ondrop
事件。
关于jquery - 如何在 `drop` 事件后停止重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8938319/