似乎 drop 事件没有在我预期的时候触发。
我假设当被拖动的元素释放到目标元素上方时,会触发 drop 事件,但情况似乎并非如此。
我有什么误解吗?
http://jsfiddle.net/LntTL/ http://jsfiddle.net/LntTL/
$('.drop').on('drop dragdrop',function(){
alert('dropped');
});
$('.drop').on('dragenter',function(){
$(this).html('drop now').css('background','blue');
})
$('.drop').on('dragleave',function(){
$(this).html('drop here').css('background','red');
})
为了让 div 元素上发生 drop 事件,您必须取消ondragenter
and ondragover
事件。使用 jquery 和您提供的代码...
$('.drop').on('drop dragdrop',function(){
alert('dropped');
});
$('.drop').on('dragenter',function(event){
event.preventDefault();
$(this).html('drop now').css('background','blue');
})
$('.drop').on('dragleave',function(){
$(this).html('drop here').css('background','red');
})
$('.drop').on('dragover',function(event){
event.preventDefault();
})
欲了解更多信息,请查看MDN 页面 https://developer.mozilla.org/en-US/docs/DragDrop/Drag_Operations#droptargets.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)