javascript Internet Explorer 中的 HTML5 拖放问题(无法访问 dataTransfer 属性)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26213011/
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
HTML5 Drag&Drop issue in Internet Explorer (dataTransfer property access not possible)
提问by netik
I'm trying to implement basic drag&drop functionality with HTML5. It works totally fine in Chrome, but in IE10 I get an 0x8000ffff - JavaScript runtime error: Unexpected call to method or property access.
error in the line setData
.
我正在尝试使用 HTML5 实现基本的拖放功能。它在 Chrome 中完全正常,但在 IE10 中,我0x8000ffff - JavaScript runtime error: Unexpected call to method or property access.
在行中出现错误setData
。
function handleDragStart(e) {
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData("dropTarget", g.destination);
}
var cols = $("#" + g.source + " tbody > tr");
[].forEach.call(cols, function (col) {
col.addEventListener('dragstart', handleDragStart, false);
});
What am I doing wrong?
我究竟做错了什么?
回答by Srneczek
For those who are looking for an answer:
对于那些正在寻找答案的人:
getData() and setData() attribute must be called exactly "text", since u can use any parameter in other browsers (which actualy makes lot of sense - IE rocks again), those other answers here are useless.
getData() 和 setData() 属性必须准确地称为“文本”,因为您可以在其他浏览器中使用任何参数(这实际上很有意义 - IE 再次摇滚),这里的其他答案无用。
回答by lkr
You are right. In IE 11 I changed from e.dataTransfer.getData('text/html') to e.dataTransfer.getData('text') and no Errors occur. Dto. in e.dataTransfer.setData('text').
你说的对。在 IE 11 中,我从 e.dataTransfer.getData('text/html') 更改为 e.dataTransfer.getData('text') 并且没有发生错误。托。在 e.dataTransfer.setData('text') 中。
This sample (the DnD methods) will then run in IE 11, Chrome and Firefox: http://www.developer.com/lang/using-html5-drag-and-drop-in-asp.net.html
此示例(DnD 方法)将在 IE 11、Chrome 和 Firefox 中运行:http: //www.developer.com/lang/using-html5-drag-and-drop-in-asp.net.html
回答by netik
Looks like I misunderstood the purpose of dataTransfer.setData
.
看来我误解了dataTransfer.setData
.
It works only like this:
它的工作原理是这样的:
e.dataTransfer.setData("Text", g.destination);
e.dataTransfer.setData("Text", g.destination);