当用户在文本框中输入查询时,我正在使用 selectize.js 提供一些建议。但是,如果不满足某些条件,我想阻止打开下拉菜单。我知道 onDropdownOpen
回调,但似乎无法从那里停止事件。以下解决方法也不起作用。
onDropdownOpen: function($dropdown) {
// [Test some variables here]
$dropdown.collapse();
}
有什么办法可以实现吗?
最佳答案
这是我试过的,似乎有效 https://plnkr.co/edit/DifihIuXoGkMxfdEht9L?p=preview
$(document).ready(function(){
$('#input-tags').selectize({
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
},
onDropdownOpen: function(){
// you can add your logic here to conditionally close the drop down
this.close();
// I had to set it to false because when it is true, this will run into infinite loop since while the input is in focus, it will trigger to open the drop down.
this.settings.openOnFocus = false;
}
});
});
关于javascript - 如果不满足某些条件,则防止打开下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41270551/