简体   繁体   English

Select2 Jquery 选择项目后删除搜索词

[英]Select2 Jquery remove searching term after selecting an item

I am using Jquery Select2 plugin for Multi Select Dropdown with Check box by referring the below code pen link.我正在使用 Jquery Select2 插件用于 Multi Select 下拉菜单,并参考下面的代码笔链接。

Ref:Please find this [codepen link][1]

https://codepen.io/faur/pen/vWVPGE https://codepen.io/faur/pen/vWVPGE

When I search for Options List as 'opt' and choosing the element from the Elements.当我将选项列表搜索为“选择”并从元素中选择元素时。 After the selection, my searched term 'opt' still showing in the input box.选择后,我的搜索词“选择”仍然显示在输入框中。 I want to clear the searched text after selecting the element.我想在选择元素后清除搜索到的文本。 How Can I do that?我怎样才能做到这一点?

在此处输入图像描述

I had the exact same problem with Select2 Version 4.1.0-beta.1 and I searched for a long time, then I found this solution which use the generic selector for the select and at the time of selection it clears the value of the search__field.我与 Select2 版本 4.1.0-beta.1 有完全相同的问题,我搜索了很长时间,然后我找到了这个解决方案,它使用了 select 的通用选择器,并且在选择时它清除了 search__field 的值. For me it worked perfectly.对我来说,它工作得很好。 Hope it will work for you too:希望它也对你有用:

    $("select").on('select2:select', function (e) {
     $('.select2-search__field').val('');
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM