【问题标题】:jQuery $(ui.draggable).remove() not working with IEjQuery $(ui.draggable).remove() 不适用于 IE
【发布时间】:2011-05-13 16:29:49
【问题描述】:

只要不是当前可拖动的对象,我就可以让 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>

【问题讨论】:

  • ui.draggable 究竟返回了什么?在那个选择器中,它不需要是所有可拖动 DOM 元素的字符串吗?如果是然后忽略这个,我在 UI 文档中找不到它。还要给页面一个 DOCTYPE,因为 IE 可能处于怪癖模式并且无法正常工作。
  • ui.draggable 是大多数 jQuery UI 拖动事件中当前拖动的元素。其实已经是jQuery对象了,不用$(ui.draggable)
  • @Darth。谢谢,每天都是学生日!

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


【解决方案1】:

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>

【讨论】:

  • 成功了!非常感激。我讨厌 IE 的特殊编码!错了!
  • ^ x 无穷大。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2021-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-17
  • 1970-01-01
  • 2016-08-09
相关资源
最近更新 更多