jQuery UI Selectable - unselect selected item on click

前端 未结 4 1844
南方客
南方客 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:53

    Well here's what I just ended up doing. I used a class name to toggle selecting and unselecting. I'd love to hear if there is another option:

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

提交回复
热议问题