在JQuery下拉列表中禁用select2插件 [英] Disable select2 plugin in JQuery dropdown
问题描述
我正在从json获取值并将其显示在弹出窗口中.我需要禁用从json获取的选项.我怎样才能做到这一点?
I am getting the values from json and displaying it in a popup. I need to disable that option which i am getting from json. How can i do that?
我尝试了普通的jQuery,但是没有用.我试过禁用真实,这也无法正常工作.
I tried normal jQuery but It doesn't work. I tried disabled true that also not working.
请提供解决方案.
推荐答案
来自select2文档
From the select2 docs
如果您需要禁用某些选项以使它们不能被select2界面选中,则现在可以将disable传递给数据:true.请注意:这也适用于来自ajax的传入值.当附加到元素时,Select2将尊重其元素的disabled属性.
In case that you need to disable certain options so that they can't be selected by the select2 interface, you can now pass in disabled: true with your data. Please note: This also works for incoming values from ajax. When attached to a element, Select2 will respect its elements' disabled property.
$( document ).ready( function() {
$( '#e24' ).select2( {
query: function( query ) {
var data = {
results: [
{ id: 1, text: "I'm selectable" },
{ id: 2, text: "I'm a disabled option", disabled: true },
{ id: 3, text: "I'm selectable too!" }
]
};
query.callback( data );
}
} );
} );
这篇关于在JQuery下拉列表中禁用select2插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!