jquery select 2 动态改变下拉宽度
jquery select 2 change dropdown width dynamically
我正在使用 jquery select 2 并且需要动态减小下拉菜单的宽度。
这是我的代码,
$('.myselect').select2();
$('.myselect').on('select2:open', function(e) {
var width = $('.select2-dropdown').width();
width -= 20;
$('.select2-dropdown').attr('style', 'width: '+width+'px !important');
});
我需要做的是将下拉菜单的宽度减少 20px。但是这个代码不起作用
只需等待 1 毫秒 :D 这可能是 select2 事件错误。
http://jsfiddle.net/4f3td9eL/
setTimeout(function(){
//code that's interacting with the dropdown
}, 1);
我正在使用 jquery select 2 并且需要动态减小下拉菜单的宽度。
这是我的代码,
$('.myselect').select2();
$('.myselect').on('select2:open', function(e) {
var width = $('.select2-dropdown').width();
width -= 20;
$('.select2-dropdown').attr('style', 'width: '+width+'px !important');
});
我需要做的是将下拉菜单的宽度减少 20px。但是这个代码不起作用
只需等待 1 毫秒 :D 这可能是 select2 事件错误。 http://jsfiddle.net/4f3td9eL/
setTimeout(function(){
//code that's interacting with the dropdown
}, 1);