问候,
我遇到了一个简单的 jQuery mousemove 函数的问题:
当我在 div 中单击并拖动时,有时浏览器会尝试像拖动图像一样“拖动”div。这仅在 Firefox(测试版本 4.0)中出现,并且对我的项目造成了严重破坏。
我把它归结为这个测试用例:
<style type="text/css" media="screen">
.box { width: 100px; height: 100px; margin: 10px; }
.red {background-color: red; }
.yellow {background-color: yellow; }
.green {background-color: green; }
.hidden { display: none; }
</style>
<div class="box red"></div>
<div class="box yellow">Can't Drag Me</div>
<div class="box green"><div class="hidden">Can't Drag Me</div></div>
要复制:单击一次 div 将其选中,然后单击并拖动。
- 红色框可拖动
- 黄框不可拖动
- 绿色框可拖动
所以问题似乎只在 div 为空或其内容被隐藏时才会出现。
谁能向我解释为什么会这样? 防止这种“拖拽”行为的最佳方法是什么?现在我知道我可以向容器中添加一个空的 div,但我想知道是否有更优雅的方法。
谢谢
最佳答案
I wasn't able to reproduce the issue in Firefox 4 ,但如果它正在发生在你身上,这应该会阻止它......
$('div').bind('dragstart', function(event) {
event.preventDefault()
});
jsFiddle .
关于javascript - 在 div 内拖动 - Firefox 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5495521/