jQuery.on(quot;dropquot;) not firing(jQuery.on(drop) 没有触发)
问题描述
我正在尝试将文件从桌面拖放到浏览器窗口.我使用 jQuery 将三个事件附加到 HTML 元素,如下面的代码所示:
I'm trying to implement drag and dropping of files from the desktop the browser window. I have used jQuery to attach three events to the HTML element as in the code below:
$("html").on("dragover", function() {
$(this).addClass('dragging');
});
$("html").on("dragleave", function() {
$(this).removeClass('dragging');
});
$("html").on("drop", function(event) {
event.preventDefault();
event.stopPropagation();
alert("Dropped!");
});
'dragover' 和 'dragleave' 事件工作正常,当我将文件拖到上方时会在整个页面周围显示一个嵌入边框,如果我再次将文件拖出则将其删除.
The 'dragover' and 'dragleave' events work fine, displaying an inset border around the entire page when I drag a file over an removing it if I drag the file out again.
但是,'drop' 事件似乎根本没有触发,拖放的文件只是在浏览器窗口中打开.
However, the 'drop' event doesn't seem to fire at all, the dropped file simply opens in the browser window.
有人知道为什么这个事件没有触发吗?
Does anyone have any idea why this event is not firing?
顺便说一句,我正在使用最新版本的 Chrome 并使用 jQuery 1.10.2 进行测试.
Btw, I am testing this in the latest version of Chrome and using jQuery 1.10.2.
推荐答案
你需要取消所有事件
$("html").on("dragover", function(event) {
event.preventDefault();
event.stopPropagation();
$(this).addClass('dragging');
});
$("html").on("dragleave", function(event) {
event.preventDefault();
event.stopPropagation();
$(this).removeClass('dragging');
});
$("html").on("drop", function(event) {
event.preventDefault();
event.stopPropagation();
alert("Dropped!");
});
这篇关于jQuery.on("drop") 没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery.on("drop") 没有触发


- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01