jQuery可拖/可拖:访问原始元素

时间:2022-12-06 15:53:34

I'm dragging elements from one unordered list to another:

我将元素从一个无序列表拖到另一个列表:

$('ul#drag li').draggable({ helper: 'clone' });
$('ul#drop').droppable({
    drop: function (event, ui) {
        ui.draggable.sourceElement.css(... ...);
    }
});

I want to mark already dragged elements in source list (but still allow dragging them), how do I access them through jQuery chain?

我想在源列表中标记已经拖拽的元素(但仍然允许拖拽),如何通过jQuery链访问它们?

I guess I can set id attribute on the dragged element, and when dropping, the cloned element would have the same id, which I can use in finding the original, but I'm sure there's a nicer solution.

我想我可以在拖动的元素上设置id属性,当删除时,克隆的元素会有相同的id,我可以用它来找到原始的元素,但是我确定有一个更好的解决方案。


2 个解决方案

#1


6  

I wonder why I did not notice that the following works, the first time I tried it:

我不知道为什么我没有注意到下面的作品,我第一次尝试的时候:

ui.draggable.css('whatever');

It's even documented:

甚至记录:

ui.draggable - current draggable element, a jQuery object.

ui。可拖动的-当前可拖动的元素,jQuery对象。

#2


5  

e.target refers to the original element

e。目标是指原始元素

#1


6  

I wonder why I did not notice that the following works, the first time I tried it:

我不知道为什么我没有注意到下面的作品,我第一次尝试的时候:

ui.draggable.css('whatever');

It's even documented:

甚至记录:

ui.draggable - current draggable element, a jQuery object.

ui。可拖动的-当前可拖动的元素,jQuery对象。

#2


5  

e.target refers to the original element

e。目标是指原始元素