select2 Events

项目中使用到select2插件,开始对select2 Events不熟,各种尝试和查阅文档,整理了以下最新的可能用到的Events

 $('select').on("change", function(e) {
// mostly used event, fired to the original element when the value changes
console.log("change val=" + e.val);
})
$('select').on("select2-opening", function() {
console.log("opening");
})
 $('select').on("select2-open", function() {
// fired to the original element when the dropdown opens
console.log("open");
})
 $('select').on("select2-close", function() {
// fired to the original element when the dropdown closes
console.log("close");
})
 $('select').on("select2-highlight", function(e) {
console.log("highlighted val=" + e.val + " choice=" + e.choice.text);
})
 $('select').on("select2-selecting", function(e) {
console.log("selecting val=" + e.val + " choice=" + e.object.text);
})
 $('select').on("select2-removed", function(e) {
console.log("removed val=" + e.val + " choice=" + e.choice.text);
})
 $('select').on("select2-loaded", function(e) {
console.log("select2-loaded");
})
 $('select').on("select2-focus", function(e) {
console.log("focus");
});
 $('select').on("select2-clearing", function(e) {
console.log("select2-clearing");
});
$el.on("select2-removing", function(e) {
console.log("select2-removing");
});
$('select').on("select2-blur", function(e) {
console.log("select2-blur");
});
 $('select').on("select2-blur", function(e) {
console.log("select2-blur");
});

PS:

  1.某些低版本可能不支持某些事件,可以使用高版本select2尝试

  2.官网提供的事件(类似:select2:select)除了change之外,其他的都没法触发,需要将中间的冒号改为"-"才可以使用

posted @ 2016-04-13 14:18  penguin521521  阅读(805)  评论(0编辑  收藏  举报