How to capture event when allowClear option of select2 is chosen?

故事扮演 提交于 2019-12-22 08:55:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!