开发者

jquery - setting a limit of items, that can be dragged into a list

i have this two lists, from which i can move items from one to another with jquery ui and connect lists, with ajax. If an item is pulled over, a message is generated in a php file and then it appears on screen. Now i want that for example the right list should be allowed to contain ten items at max. It would be great if it would be possible with jquery, that if there is already ten items in the list and you go and drag the eleventh, if then the item would somehow vanish, maybe with a little effekt. I think maybe reading out db in the php-file if theres already ten items, and so on. But i have currently no idea, if and in case if in which way, jqu开发者_如何学Cery would support this kind of behaviour. Can you give me some advise?

Greetings, maschek


Using the example from http://docs.jquery.com/UI/Droppable, you can do:

    $("#draggable").draggable();

    $("#droppable").droppable({
      drop: function() { 
          if($("#draggable").children().length > 10)
            return;
      }
    });

Ore something along that line.


You could select all the items in your list using jquery and then use the length property to find out how many were actually selected. This would let you check how big your list is. E.g:

if ( $('#yourlist li').length() == 10 )
{
    // Do effect here
}


sometimes its so easy. Just putting a "greedy:true," into the deroppable-definition and it works fine.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜