对HTML元素禁用拖放? [英] Disable Drag and Drop on HTML elements?

查看:188
本文介绍了对HTML元素禁用拖放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个web应用程序,我试图实现一个全功能的窗口系统。现在它很顺利,我只遇到一个小问题。有时,当我去拖动我的应用程序的一部分(通常是我的窗口的角落div,这是应该触发一个调整大小的操作),Web浏览器变得聪明,并认为我的意思是拖放一些东西。最终结果,我的操作被搁置,而浏览器执行拖放操作。

I'm working on a web application for which I'm attempting to implement a full featured windowing system. Right now it's going very well, I'm only running into one minor issue. Sometimes when I go to drag a part of my application (most often the corner div of my window, which is supposed to trigger a resize operation) the web browser gets clever and thinks I mean to drag and drop something. End result, my action gets put on hold while the browser does its drag and drop thing.

有一个简单的方法来禁用浏览器的拖放?我理想地希望能够在用户点击某些元素时关闭它,但重新启用它,以便用户仍然可以在我的窗口的内容上使用他们浏览器的正常功能。我使用jQuery,虽然我不能找到它浏览文档,如果你知道一个纯jQuery解决方案,这将是非常好的。

Is there an easy way to disable the browser's drag and drop? I'd ideally like to be able to turn it off while the user is clicking on certain elements, but re-enable it so that users can still use their browser's normal functionality on the contents of my windows. I'm using jQuery, and although I wasn't able to find it browsing the docs, if you know a pure jQuery solution it would be excellent.

简而言之:我需要禁用浏览器文本选择和拖放功能,而我的用户有鼠标按钮,并在用户释放鼠标时恢复该功能。

In short: I need to disable browser text selection and drag-and-drop functions while my user has the mouse button down, and restore that functionality when the user releases the mouse.

谢谢

推荐答案

尝试阻止mousedown事件的默认值:

Try preventing default on mousedown event:

<div onmousedown="event.preventDefault ? event.preventDefault() : event.returnValue = false">asd</div>

<div onmousedown="return false">asd</div>

这篇关于对HTML元素禁用拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆