I've tried to capture select2:clearing
event
$("#my-select").on("select2:clearing", function (e) {
console.log('cleared');
});
(jsfiddle)
but it is not fired. I've also tried other versions (like select2:removed
etc., see another question with similar problem), but it also doesn't work.
I use select2 4.0.0-beta2.
The changelog of select2 4.0.0-beta2 states:
Removed events
select2-clearing - Use select2:unselecting instead
This works:
$("#my-select").on("select2:unselecting", function(e) {
});
$("#my-select").on("select2:select select2:unselecting", function(e) {
//do something here
});
来源:https://stackoverflow.com/questions/28065551/how-to-capture-event-when-allowclear-option-of-select2-is-chosen