微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

文件放入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 and dragover 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事件.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐