0

我想将已删除的项目附加到可排序列表中的目标可放置框中,但我无法将已删除的项目附加到特定元素中。

我的jQuery,

$(".sortable").sortable({
    update: function(){
    // php update.
    }
}).disableSelection();


$( ".droppable" ).droppable({
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function( event, ui ) {

        var targetElem = $(this).attr("id");

        $( this )
            .addClass( "ui-state-highlight" )
            .find( "p" )
            .html( "Dropped! inside " + targetElem );

            alert(targetElem);

        var container = $( this ).find( "ul.dropped-items" ).css({border:"blue solid 1px"});

        container.append(ui.draggable.clone());

        ui.draggable.remove();

    }
});

丢弃的项目应附加到此元素中,

<ul class="dropped-items">
</ul>

但它只是没有发生。我错过了什么,我怎样才能让它发挥作用?

jsfiddle 测试页面

4

1 回答 1

0

您可以删除元素上的绝对位置样式:

Javascript

...
container.append(ui.draggable.clone().css({position: 'relative', left: 0, top: 0, width: 'auto', height: 'auto'}));
...

演示

或者,添加样式以执行相同操作:

CSS

.dropped-items li {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
    width: auto !important;
    height: auto !important;
}

演示

于 2012-12-14T00:49:59.930 回答