drag and drop not working in IE - Javascript, HTML5

后端 未结 4 1734
自闭症患者
自闭症患者 2020-12-19 11:09

I\'ve built this checker-board app which uses HTML5\'s Drag&Drop with javascript. It works great on chrome and firefox, but not on IE9 or IE8. My guess is that the probl

4条回答
  •  执念已碎
    2020-12-19 11:42

    IE is a bit different than most, try ondragstart, ondragenter, etc..

                allSquares[i].attachEvent('ondragstart', handleDragStart);
                allSquares[i].attachEvent('ondragenter', handleDragEnter);
                allSquares[i].attachEvent('ondragover', allowDrop);
                allSquares[i].attachEvent('ondragleave', handleDragLeave);
                allSquares[i].attachEvent('ondrop', handleDrop);
    

    EDIT:

    function handleDragStart(e){
        if(!e)
           e = window.event;
    
        dragSrcEl = (window.event) ? window.event.srcElement /* for IE */ : event.target;
        e.dataTransfer.effectAllowed = 'copy';
        e.dataTransfer.setData('text/html', dragSrcEl.innerHTML);
    }
    

提交回复
热议问题