2

只要它不是当前的可拖动对象,我就可以让 IE 删除对象。这适用于 Chrome 和 Firefox。有什么我做错了吗?

<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>
4

1 回答 1

2

ui.draggable 和 drop 函数在 IE 中有点古怪。试试这个:

<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>
于 2011-05-13T17:03:42.260 回答