如何动态地将select2组合框设置为只读?
这是我到目前为止所尝试的:
$('...').attr({'readonly': 'readonly'}).trigger('change.select2');
$('...').attr({'readonly': 'readonly'}).trigger('change');
$('...').select2().enable(false);
Ali Jamal.. 13
这是最新的解决方案select2
(已通过测试4.0.7
),使用css only
/*Select2 ReadOnly Start*/ select[readonly].select2-hidden-accessible + .select2-container { pointer-events: none; touch-action: none; } select[readonly].select2-hidden-accessible + .select2-container .select2-selection { background: #eee; box-shadow: none; } select[readonly].select2-hidden-accessible + .select2-container .select2-selection__arrow, select[readonly].select2-hidden-accessible + .select2-container .select2-selection__clear { display: none; } /*Select2 ReadOnly End*/
lafeber.. 10
Select2的解决方案- 问题#3387 - Readonly支持:
select[readonly].select2 + .select2-container {
pointer-events: none;
touch-action: none;
.select2-selection {
background: #eee;
box-shadow: none;
}
.select2-selection__arrow,
.select2-selection__clear {
display: none;
}
}
Cas Knook.. 9
参见:http : //select2.github.io/select2/
我这样做:
$("#modelname-fieldname").select2({disabled:readonly});
哪里:
modelname-fieldname
如下所示: $form -> field($modelname, "fieldname") -> widget(Select2::classname(), [ ... ]);
readonly
是true,false或字符串 readonly
(可选)您可以将鼠标悬停在该select2
字段上时更改光标。
这是最新的解决方案select2
(已通过测试4.0.7
),使用css only
/*Select2 ReadOnly Start*/ select[readonly].select2-hidden-accessible + .select2-container { pointer-events: none; touch-action: none; } select[readonly].select2-hidden-accessible + .select2-container .select2-selection { background: #eee; box-shadow: none; } select[readonly].select2-hidden-accessible + .select2-container .select2-selection__arrow, select[readonly].select2-hidden-accessible + .select2-container .select2-selection__clear { display: none; } /*Select2 ReadOnly End*/
Select2的解决方案- 问题#3387 - Readonly支持:
select[readonly].select2 + .select2-container {
pointer-events: none;
touch-action: none;
.select2-selection {
background: #eee;
box-shadow: none;
}
.select2-selection__arrow,
.select2-selection__clear {
display: none;
}
}
参见:http : //select2.github.io/select2/
我这样做:
$("#modelname-fieldname").select2({disabled:readonly});
哪里:
modelname-fieldname
如下所示: $form -> field($modelname, "fieldname") -> widget(Select2::classname(), [ ... ]);
readonly
是true,false或字符串 readonly
(可选)您可以将鼠标悬停在该select2
字段上时更改光标。