如何在删除最后一个可拖动元素后执行操作..

时间:2014-05-19 12:12:23

标签: javascript jquery jquery-ui drag-and-drop

在最后一次放下操作后(可放置的元素编号总是不同)我想显示例如提交按钮。

这是一个工作示例(相应部分):

$('.unsortedChoiceBox1 li').draggable({
    appendTo: "body",
    helper: "clone",
    revert: true,
    scope: "d1",
});

$( "#droppable1 ol" ).droppable({
    scope: "d1",
    activeClass: "ui-state-default",
    hoverClass: "ui-state-hover",
    accept: '.unsortedChoiceBox1 li',
    drop: function( event, ui ) {
        ui.draggable.draggable('option','revert',false); 
        ui.draggable.clone().appendTo(this);
        ui.draggable.remove();

    }
});

请给我一个想法:如何检测哪个可拖动元素是最后一个?

1 个答案:

答案 0 :(得分:0)

这是代码。你需要在drop事件上计算drag element和increment counter

    $('.unsortedChoiceBox1 li').draggable({
                appendTo: "body",
                helper: "clone",
                revert: true,
                scope: "d1",
            });
            var count = 0;
var drags = $('.unsortedChoiceBox1 li').size();
            $("#droppable1 ol").droppable({
                scope: "d1",
                activeClass: "ui-state-default",
                hoverClass: "ui-state-hover",
                accept: '.unsortedChoiceBox1 li',
                drop: function(event, ui) {
                    ui.draggable.draggable('option', 'revert', false);
                    ui.draggable.clone().appendTo(this);
                    ui.draggable.remove();
                    count++;
                    if (drags == count) {
                        alert('all elements are dropped');
                        //show submit button
                    }

                }
            });