问题
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.
回答1:
The changelog of select2 4.0.0-beta2 states:
Removed events
select2-clearing - Use select2:unselecting instead
https://github.com/select2/select2/releases
回答2:
This works:
$("#my-select").on("select2:unselecting", function(e) {
});
回答3:
$("#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