Propagation Issue In Nested Jquery Ui Selectable

后端 未结 2 629

Problem is: In nested jQuery Ui selectable, selecting top most child of context means when I click on Item 1 it select Item 1, but when I click on Item 111 or 1111 it select

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 07:04

    I suppose jQuery UI Selectable is not designed for such behaviour. But you still can do it manually:

    $(document).ready(function()
    {
        $("*").click(function()
        {
            $(".ui-selected").removeClass("ui-selected");
            var thisEl = $(this);
            if (thisEl.closest("#selectable").length)
            {
                thisEl.addClass("ui-selected");
            }
            return false;
        });
    });
    

    Updated fiddle.

    Also to emulate jQuery UI Selectable (and to use its styles) you can add something like:

    $(document).ready(function()
    {
        var selectable = $("#selectable");
        selectable.addClass("ui-selectable");
        selectable.find("*").addClass("ui-selectee");
    });
    

提交回复
热议问题