开发者

jQuery UI, droppable , accept maximum number of elements

开发者 https://www.devze.com 2023-02-03 05:19 出处:网络
is there any way to set the maximum elements the drop target can accept ? an开发者_开发问答d is there any standard way to list all the dropped items ??

is there any way to set the maximum elements the drop target can accept ?

an开发者_开发问答d is there any standard way to list all the dropped items ??

thanks


Just use a counter on the drop event to disable the droppable when the limit is reached:

$(function() {
    var limit = 5;
    var counter = 0;
    $('.drag').draggable({revert: "invalid"});
    $('.drop').droppable({
        drop: function() {
            counter++;
            if (counter == limit) {
                alert('limit reached!');
                $(this).droppable("disable");
            }
        }
    });
});

Example link. Please note that this is only a demo, you may probably need to use accept and scope options.

0

精彩评论

暂无评论...
验证码 换一张
取 消