jquery html 5 dragstart .on('dragstart',function(e){}) e.dataTransfer.setData() doesn't work

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 14:51:11

问题


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.

I used 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


回答1:


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. dont' forget to set the draggable="true" attribute for the element to be dragged.




回答2:


jQuery creates it's own event object, and it doesn't have a dataTransfer property yet. This adds dataTransfer to the event object.

$.event.props.push('dataTransfer');



来源:https://stackoverflow.com/questions/13949422/jquery-html-5-dragstart-ondragstart-functione-e-datatransfer-setdata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!