Javascript jquery html 5 dragstart .on('dragstart',function(e){}) e.dataTransfer.setData() 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13949422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery html 5 dragstart .on('dragstart',function(e){}) e.dataTransfer.setData() doesn't work
提问by zsytssk
chrome throw err: Cannot call method 'setData' of undefined, I find the e is not equal to window.event(it havn't propert dataTransfer);both has very big different
chrome throw err:无法调用未定义的方法“setData”,我发现 e 不等于 window.event(它没有属性 dataTransfer);两者有很大不同
I find both almost equal in the click event.
我发现两者在点击事件中几乎相等。
I used http://code.jquery.com/jquery-latest.js.
我使用了http://code.jquery.com/jquery-latest.js。
I don't use drag feature,I just want know why. it is new feature in html 5,jquery still behind of it ?. or jquery team don't want support it?? or some other reason
我不使用拖动功能,我只是想知道为什么。它是 html 5 中的新功能,jquery 仍然落后于它吗?。或者 jquery 团队不想支持它??或其他一些原因
回答by John Doe
In the callback function you get a jQuery wrapper over a native event. Use the originalEventproperty of passed argument:
在回调函数中,您将获得一个覆盖本机事件的 jQuery 包装器。使用originalEvent传递参数的属性:
$('...').on('dragstart', function (event) {
event.originalEvent.dataTransfer.setData('...', '...');
});
P.S. dont' forget to set the draggable="true"attribute for the element to be dragged.
PS 不要忘记draggable="true"为要拖动的元素设置属性。
回答by two7s_clash
jQuery creates it's own event object, and it doesn't have a dataTransfer property yet. This adds dataTransfer to the event object.
jQuery 创建它自己的事件对象,并且它还没有 dataTransfer 属性。这将 dataTransfer 添加到事件对象。
$.event.props.push('dataTransfer');
$.event.props.push('dataTransfer');

