What is the data type in HTML 5 if i need to drag and drop a div to another div?

核能气质少年 提交于 2019-12-12 02:16:40

问题


in the JS function below, the data type is set as "text" but this doesn't work because i'm looking at dragging and dropping a div. Is there any way around this? or a data type ?

function drag(ev) { ev.dataTransfer.setData('Text', ev.target.id); }

Thanks so much.


回答1:


Mozilla recommend application/x-moz-node for dragging nodes within the document, though that is obviously only going to work in Gecko based browsers. It's easier and generally more compatible to set a reference to the element as text, like you're doing already, and then use the reference to grab the element in the drop event and move it in code to the correct location.



来源:https://stackoverflow.com/questions/14291590/what-is-the-data-type-in-html-5-if-i-need-to-drag-and-drop-a-div-to-another-div

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