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") 没有触发
基础教程推荐
- 检查 HTML5 拖放文件类型 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
