jQuery $(ui.draggable).remove() not working with IE

好久不见. 提交于 2019-12-13 15:24:12

问题


I can get IE to remove objects as long as it is not the current draggable object. This is working on Chrome and Firefox. Is there something I'm doing wrong?

<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="http://code.jquery.com/ui/jquery-ui-git.js"></script>
</head>
<body>
    <ul id="list">
    <li id="test-1" class="dropme">One</li>
    <li id="test-2" class="dropme">Two</li>
    </ul>
    <div id="bucket" style="border:1px solid black">
        <p>Drop items here and they should be removed.</p>
    </div>
    <script>
        $("#list").sortable({
        items: 'li'
    });   
    $('#bucket').droppable({
        drop: function(event, ui) {
            $(ui.draggable).remove();
        },
        accept: '.dropme'
    });   
    </script>
</body>
</html>

回答1:


The ui.draggable and drop function are a little quirky in IE. Try this:

<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="http://code.jquery.com/ui/jquery-ui-git.js"></script>
    <script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
</head>
<body>
    <ul id="list">
    <li id="test-1" class="dropme">One</li>
    <li id="test-2" class="dropme">Two</li>
    </ul>
    <div id="bucket" style="border:1px solid black">
        <p>Drop items here and they should be removed.</p>
    </div>
    <script>
        $("#list").sortable({
        items: 'li',
        stop: function(event, ui) { 
            if (deleteMe) {
                        ui.item.remove();
                        deleteMe = false;
                    }
        }
    });   
    $('#bucket').droppable({
        drop: function(event, ui) {
            deleteMe = true; 
        },
        accept: '.dropme'
    });   
    </script>
</body>
</html>


来源:https://stackoverflow.com/questions/5994990/jquery-ui-draggable-remove-not-working-with-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!