问题
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