jQuery Sortable-列表中的项目数限制 [英] jQuery Sortable - Limit number of items in list

查看:206
本文介绍了jQuery Sortable-列表中的项目数限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个计划表,我正在使用jQuery Sortable进行编辑.

I have a schedule table I'm using jQuery Sortable for editing.

每天都是UL,每个事件都是LI.

Each day is a UL, and each event is an LI.

我的jQuery是:

    $("#colSun, #colMon, #colTue, #colWed, #colThu").sortable({
         connectWith: '.timePieces',
         items: 'li:not(.lith)'
    }).disableSelection();

使所有LI都可排序,但那些具有"lith"类(日期名称)的LI除外. 用户可以每天拖动事件,也可以通过单击按钮添加新事件,该按钮会将新的可拖动事件(LI)附加到第一个UL(星期日).

To make all LI's sortable except those with class "lith" (day names). User can drag an event from day to day, or add new events by clicking a button, which appends a new draggable event (LI) to the fist UL (Sunday).

我希望每天最多只接受10个事件. 我该怎么做?

I want to make each day accept only up to 10 events. How do I do this?

提前谢谢!

推荐答案

  • DEMO: http://so.lucafilosofi.com/jquery-sortable-limit-number-of-items-in-list

$(function() {
    $(".sortables").sortable({
        connectWith: '.connectedSortable',
        //receive: This event is triggered when a
        //connected sortable list has received an item from another list.
        receive: function(event, ui) {
            // so if > 10
            if ($(this).children().length > 10) {
                //ui.sender: will cancel the change.
                //Useful in the 'receive' callback.
                $(ui.sender).sortable('cancel');
            }
        }
    }).disableSelection();
});

这篇关于jQuery Sortable-列表中的项目数限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆