How to prevent multiple selection in jQuery UI Selectable plugin

前端 未结 10 1862
走了就别回头了
走了就别回头了 2020-12-30 00:13

I am using jQuery UI Selectable plugin. I want to select one item at a time. But jQuery UI Selectable plugin allows multiple selection by clicking/ dragging / holding CTRL

10条回答
  •  半阙折子戏
    2020-12-30 00:31

    What i did, is that i allow multiple selection but when the selection is done, i only keep the first element selected

    • Row 1
    • Row 2
    • Row 3

    This selects all the selected elements except the first one and deletes the selected status. So at the end, only one element will be selected. event.target corresponds to my ul element.

    $('#select').selectable({
        stop:function(event, ui){
            $(event.target).children('.ui-selected').not(':first').removeClass('ui-selected');
        }
    });
    

    I know this topic is kinda old, but i still stumbled upon it, so it can be useful to someone else

提交回复
热议问题