jQuery $(ui.draggable).remove() 不适用于 IE

标签 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>

最佳答案

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

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

关于jQuery $(ui.draggable).remove() 不适用于 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5994990/

相关文章:

javascript - jQuery 自动完成,3 个值或更多

jQuery UI 可拖动 : get the underlaying element at drag-stop

jquery - 在 droppable 上使用 if/else 更改 CSS 类

javascript - 使用键从 json 数组中获取 json 对象

javascript - jQuery - 提交表单联系人后的占位符值

javascript - 将下拉菜单变成jquery slider

javascript - jquery ui 主题创建自定义 jqueryui.js 文件

javascript - Jquery 日期选择器。 2 个日期选择器。限制范围。默认日期 当前日期

javascript - jquery + 格式化表格单元格中的颜色

jquery-ui - 创建 jQuery UI 小部件后如何更改其选项?