如何使 select2 只读? [英] How make select2 readonly?

查看:183
本文介绍了如何使 select2 只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 select2 不存在只读"功能.请查看此处.我如何做到这一点?任何帮助,将不胜感激.谢谢.注意:我不能使用禁用.如果我使用禁用,我将不会获得所选值的列表.

I know that "readonly" feature does not exist for select2. Please check here. How do I achieve that? Any help would be appreciated. Thanks. Note: I cant use disabled. If I use disabled, I will not get the list of selected value.

推荐答案

我猜这个问题已经解决,或者可以用于更高版本,因为这对我有用.

I guess that issue is resolved or may be available for higher version as this worked for me.

请仔细阅读示例以在此处将 select2 设为只读:Select 2

Please go through the example to make a select2 readonly here: Select 2

在js代码中:

$("select").select2("readonly", true);

你可以把你自己的 CSS 像这样:

You can put your own CSS like:

.select2-container.select2-container-disabled .select2-choice {
  background-color: #ddd;
  border-color: #a8a8a8;
}

这篇关于如何使 select2 只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆