use*_*r10 3 javascript html5 internet-explorer drag-and-drop
我尝试拖放HTML.除了IE9之外,它在所有浏览器中都运行良好(不需要低于IE9).IE9中未触发ondrop事件.
任何帮助?这是我的代码.
提前致谢.
如果div用a标签替换它会起作用.但是,您应该进行其他一些更改,首先a通过false在onclick事件中返回来确保标记不是可点击的链接:
<a class="div123" href="#" draggable="true"
ondragstart="handleDragStart(event)"
ondrop="handleDrop(event)"
ondragover="dragoveHandler(event)"
onclick="return false;">
HTML5 drag and drop
</a>
Run Code Online (Sandbox Code Playgroud)
其次,IE9不接受text/plainin的参数setData,Text改为使用或添加数据try...catch.此外,您应该确保您添加的数据实际上是文本:
e.dataTransfer.setData("Text", "" + $(e.target).index());
Run Code Online (Sandbox Code Playgroud)
最后你的handleDrop函数需要preventDefault/ return false因为否则删除链接(a元素`)的默认操作是导航到删除的URL:
function handleDrop(e) {
alert($(e.target).index());
if (e.preventDefault) {
e.preventDefault(); // Necessary. Stops redirect.
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6011 次 |
| 最近记录: |