拖放在IE中不起作用

时间:2014-01-02 09:45:13

标签: javascript html

以下拖放JavaScript适用于Firefox,但不适用于IE:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>t</title>
    <style type="text/css"> 
       .mover { 
           width:60px; height:4em; line-height:4em; margin:10px; padding:5px;
           float:left; background:#ffff99; border:1px dotted #333333; text-align:center;
        } 
    </style> 
    <script type="text/javascript">
    function dragWord(dragEvent) {
        dragEvent.dataTransfer.setData("text/html", dragEvent.target.textContent + "|" + dragEvent.target.parentNode.id);
    }
    function dropWord(dropEvent) {
        var dropData = dropEvent.dataTransfer.getData("text/html"); var dropItems = dropData.split("|");
        var prevElem = document.getElementById(dropItems[1]);
        prevElem.getElementsByTagName("div")[0].textContent = dropEvent.target.textContent;
        dropEvent.target.textContent = dropItems[0]; dropEvent.preventDefault();
    }
    </script>
    </head>

    <body>
    <div><em>Move the words around to make a sentence.</em></div> 
    <form>
        <div id="box1" ondragover="event.preventDefault()" ondrop="dropWord(event)"> 
            <a href="#" class="mover" draggable="true" ondragstart="dragWord(event)" >page</a>
        </div>
    </form>
</html>

有没有人知道为什么这在IE中不起作用?问题在于拖放功能。我试图用href =#替换div但是这不起作用。

0 个答案:

没有答案