简体   繁体   English

HTML5拖放Chrome中的错误

[英]HTML5 Drag and drop bug in chrome

I am trying to implement drag and drop feature in my website, but after few hours of trying i came to conclusion that there is a bug in chrome, for example try this example and see for your self. 我正在尝试在我的网站中实现拖放功能,但经过几个小时的尝试后,我得出结论,铬有一个错误,例如尝试这个例子 ,看看你的自己。

It seems that dataTransfer property doesn't exist therefore i'm getting undefined error. 似乎dataTransfer属性不存在因此我得到未定义的错误。

Here is my code: 这是我的代码:

$(document).on("dragover", "#dropFile", function(e){
    e.dataTransfer.setData('text/x-example', 'Foobar'); //error
    return false; 
});

$(document).on("drop", "#dropFile", function(e){
    e.preventDefault();

    console.log(e.dataTransfer); //error
});

PS this does work in firefox. PS这适用于Firefox。

I've just been dabbling with drag-drop lately, and my primary browser is chrome and things work great so far. 我最近一直在涉及拖放,我的主要浏览器是chrome,到目前为止工作效果很好。 The method I use to wire up the events is a bit different from yours 我用来连接事件的方法与你的有点不同

  $(".droppable").bind("dragover", function (e)
  {
    // do stuff here
  });
  $(".droppable").bind("drop", function (e)
  {
    // do stuff here
  })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM