jQuery $(ui.draggable).remove()不使用IE

时间:2011-05-13 16:29:49

标签: jquery jquery-ui jquery-ui-draggable jquery-ui-sortable

我可以让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>

1 个答案:

答案 0 :(得分: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>