我正在使用具有maximumSelectionSize: 1
属性的select2插件。选择1后,窗体上仍然存在一个事件,该事件使用户可以单击框的外部,并且将显示一条消息:“您只能选择1个项目”。
我完全不想要此消息。有什么办法可以确保它永远不会出现?
编辑-根据要求发布的代码:
$('.select2-select').select2({
maximumSelectionSize: 1
});
编辑2:aaand小提琴:http://jsfiddle.net/s85k7tg7/
您可以使用select2-opening
事件来防止在选定项目时打开下拉列表。
$('.select2-select').select2({
maximumSelectionSize: 1
}).on('select2-opening', function(e) {
if ($(this).select2('val').length > 0) {
e.preventDefault();
}
});
$('。select2-select')。select2({maximumSelectionLength:1});