将文件放入Firefox中的div后,网页将被重定向到此文件.我试图在drop handler中使用jQuery的e.preventDefault()来阻止这种传播,但是失败了.
请参阅this demo,将文件放入#test不会重定向网页,但是进入#test1会,我想知道原因.我是否应该始终将处理程序绑定到dragenter,dragover,dragleave和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.
但是我在firefox上测试this demo,#test的工作和#test1没有,似乎Mozilla犯了一个错误,而html5doctor是对的:Firefox需要dragover才能让drop工作.
解决方法
需要在Google Chrome和Safari中取消ondragover事件才能启动ondrop事件.