select2 4.0.3 tab focus解决
原创
©著作权归作者所有:来自51CTO博客作者Hello_Martin的原创作品,请联系作者获取转载授权,否则将追究法律责任
$(document).on("focus", ".select2", function (e) {
if (e.originalEvent) {
var s2element = $(this).siblings("select:enabled");
s2element.select2("open");
// Set focus back to select2 element on closing.
s2element.on("select2:closing", function () {
if (s2element.val()) s2element.select2("focus");
});
}
});
如果出现多选选择异常的话
补充一下:
$(document).on("focus", ".select2", function (e) {
if (e.originalEvent) {
var s2element = $(this).siblings("select:enabled");
s2element.select2("open");
// Set focus back to select2 element on closing.
s2element.on("select2:closing", function () {
if (s2element.val()) s2element.select2("focus");
});
}
});