jquery html 5 dragstart .on('dragstart',function(e){})e.dataTransfer.setData()不起作用 [英] jquery html 5 dragstart .on('dragstart',function(e){}) e.dataTransfer.setData() doesn't work
问题描述
chrome throw err:无法调用未定义的方法'setData',
我发现e不等于window.event(它没有属性dataTransfer);两者都有很大的不同
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
我发现在点击事件中两者几乎相等。
I find both almost equal in the click event.
我使用了 http://code.jquery.com/jquery-latest.js 。
I不要使用拖动功能,我只想知道原因。
它是html 5中的新功能,jquery仍然落后于它?
或jquery团队不想要支持吗?或其他原因
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
推荐答案
在回调函数中,您将获得原生事件的jQuery包装器。使用传递参数的 originalEvent
属性:
In the callback function you get a jQuery wrapper over a native event. Use the originalEvent
property of passed argument:
$('...').on('dragstart', function (event) {
event.originalEvent.dataTransfer.setData('...', '...');
});
P.S。不要忘记为要拖动的元素设置 draggable =true
属性。
P.S. dont' forget to set the draggable="true"
attribute for the element to be dragged.
这篇关于jquery html 5 dragstart .on('dragstart',function(e){})e.dataTransfer.setData()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!