jQuery UI Selectable - unselect selected item on click

前端 未结 4 1838
南方客
南方客 2020-12-24 15:24

Does anyone know if there\'s a way to configure a jquery ui selectable element to unselect the selected element when you click it? Sort of like a toggle. If it\'s already

4条回答
  •  情歌与酒
    2020-12-24 15:57

    If you want that existing selections be preserved and yet have the toggle operation, you simply need to ignore the unselected event for the solution given. Also you need to remove the ui-selected class.

    $("#selectable").selectable({
    selected: function (event, ui) {
        if ($(ui.selected).hasClass('selectedfilter')) {
            $(ui.selected).removeClass('selectedfilter').removeClass('ui-selected');
            // do unselected stuff
        } else {            
            $(ui.selected).addClass('selectedfilter').addClass('ui-selected');
            // do selected stuff
        }
    }
    });
    

提交回复
热议问题