dataTransfer.setData在IE9中不起作用 [英] dataTransfer.setData does not work in IE9
问题描述
我将一些代码绑定到这样的jquery的 dragstart
事件:
I am binding some code to the dragstart
event with jquery like this:
$new.on('dragstart', function(event) {
event.originalEvent.dataTransfer.setData("text/html", $new.clone().wrap('<p>').parent().html());
});
$ new
是一个jquery对象。目的是将拖动的元素的HTML附加到事件,以便我可以在删除时创建一个副本。 Chrome甚至不需要这个事件。当添加此代码时,Firefox可以工作。但IE9会抛出一个 SCRIPT65535:意外调用方法或属性访问。
当触发事件时。这是一个jsFiddle: http://jsfiddle.net/j52EM/3/
$new
is a jquery object. The aim is to attach the html of the dragged element to the event, so that i can create a copy when dropped. Chrome doesn't even need this event to do it. Firefox works when this code is added. But IE9 throws a SCRIPT65535: Unexpected call to method or property access.
when the event is triggered. Here is a jsFiddle: http://jsfiddle.net/j52EM/3/
我如何使这个工作适用于IE?
How can i make this work for IE?
推荐答案
在ie中只有两个参数href =http://msdn.microsoft.com/en-us/library/ie/ms536744%28v=vs.85%29.aspx> docs IE9不接受text / html格式。使用'文本'
in ie there's only two parameters according to the docs IE9 does not accept text/html as a format. USe just 'Text'
这里是一个样本,即根据msdn网站:
here's a sample ie according to the msdn website:
function InitiateDrag()
// The setData parameters tell the source object
// to transfer data as a URL and provide the path.
{
event.dataTransfer.setData("URL", oImage.src);
}
function FinishDrag()
// The parameter passed to getData tells the target
// object what data format to expect.
{
sImageURL = event.dataTransfer.getData("URL")
oTarget.innerText = sImageURL;
}
这篇关于dataTransfer.setData在IE9中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!