[英]HTML drag and drop in IE9
I tried drag and drop in HTML. 我尝试拖放HTML。 It is working good in all browsers except IE9 (no need to work on lower than IE9). 除了IE9之外,它在所有浏览器中都运行良好(不需要低于IE9)。 ondrop event is not triggered in IE9. IE9中未触发ondrop事件。
any help? 任何帮助? here is my code. 这是我的代码。
Thanks in advance. 提前致谢。
It'll work if you replace div
with a
tags. 如果更换它会工作div
有a
标签。 However there are a couple of other changes you ought to make, firstly make sure that the a
tags aren't clickable links by returning false
in the onclick
event: 但是,您还应该进行其他一些更改,首先通过在onclick
事件中返回false
来确保a
标签不是可点击的链接:
<a class="div123" href="#" draggable="true"
ondragstart="handleDragStart(event)"
ondrop="handleDrop(event)"
ondragover="dragoveHandler(event)"
onclick="return false;">
HTML5 drag and drop
</a>
Secondly, IE9 doesn't accept parameters of text/plain
in setData
, use Text
instead or add the data inside of a try...catch
. 其次,IE9不接受setData
中text/plain
参数,而是使用Text
代替或者在try...catch
添加数据。 Also, you should make sure the data you're adding is actually text: 此外,您应该确保您添加的数据实际上是文本:
e.dataTransfer.setData("Text", "" + $(e.target).index());
Finally your handleDrop
function needs to preventDefault
/ return false
because otherwise the default action for dropping a link (an a
element`) is to navigate to the dropped URL: 最后你的handleDrop
函数需要preventDefault
/ return false
,否则删除链接( a
元素`)的默认操作是导航到被删除的URL:
function handleDrop(e) {
alert($(e.target).index());
if (e.preventDefault) {
e.preventDefault(); // Necessary. Stops redirect.
}
return false;
}
Here is a jsFiddle of your code which will work in IE9 . 这是一个可以在IE9中运行的代码的jsFiddle 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.