【问题标题】:Get the item/object where the element is dropped获取元素被删除的项目/对象
【发布时间】:2012-03-06 13:40:37
【问题描述】:

我正在编写一个包含三个列表的任务面板,并使用 sortable 在它们之间移动项目。但我需要拿起元素被丢弃的项目。我知道ui.item 是被丢弃的元素,但我不知道我把它丢弃在哪里。这是我的代码:

$( ".column" ).sortable({
    receive: function(event, ui) {
        /* get the element where ui.item is dropped */
    }
});

我知道带有.column 选择器的元素可以是任意的,但是如何选择!!!

【问题讨论】:

标签: javascript jquery jquery-ui jquery-ui-sortable


【解决方案1】:

编辑 - 这样做的方法是这样的

$("#sortable1, #sortable2").sortable({
    connectWith: ".connectedSortable",
    receive: function(e, ui) {
        alert(ui.item.closest('ul').attr('id'));

    }
}).disableSelection();

当然,如果你不想让被删除元素旁边的元素得到,你会这样做

ui.item.closest('ul')

在这里摆弄http://jsfiddle.net/dKaYM/

【讨论】:

  • 如果我想滑动位置而不是我需要添加什么?
【解决方案2】:

非常简单:

alert($(this).attr('id')); //this is element where the item was dropped in 

【讨论】:

  • 这似乎是正确的。见stackoverflow.com/questions/4420311/…。
  • 这是一个很老的问题,但就我而言,我一直在寻找这个,我终于做到了:)。谢谢
  • 实际上,$(this) 是项目被拖出的元素,而不是它被放入的元素...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-03
  • 1970-01-01
  • 2016-08-05
  • 1970-01-01
  • 2022-08-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多