Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从引导数据库中删除活动搜索时选择2_Javascript_Jquery_Css_Twitter Bootstrap - Fatal编程技术网

Javascript 从引导数据库中删除活动搜索时选择2

Javascript 从引导数据库中删除活动搜索时选择2,javascript,jquery,css,twitter-bootstrap,Javascript,Jquery,Css,Twitter Bootstrap,我正在我的一个项目中使用引导选择器- 这是我的密码 <select class="selectpicker" data-live-search="true" multiple data-actions-box="true"> <option data-tokens="ketchup mustard">Hot Dog, Fries and a Soda</option> <option data-tokens="mustard">Burger

我正在我的一个项目中使用引导选择器-

这是我的密码

<select class="selectpicker" data-live-search="true" multiple data-actions-box="true">
  <option data-tokens="ketchup mustard">Hot Dog, Fries and a Soda</option>
  <option data-tokens="mustard">Burger, Shake and a Smile</option>
  <option data-tokens="frosting">Sugar, Spice and all things nice</option>
</select>
我有一个问题,当我在下拉列表中搜索时,最前面的搜索项目会高亮显示(蓝色),而没有选择。我只想在点击时激活该类,而不是在搜索条件中。有什么办法吗?
这是我的JSFIDLE,因为您的是一个特例,它在搜索时动态删除
.active
。您需要将搜索输入上的
.on('input')
事件侦听器作为目标,并从下拉列表中删除
活动类。像这样

$(function() {
   //This event is fired when the dropdown has been made visible to the user
   $('.selectpicker').on('shown.bs.select', function (e) {
     $('ul.dropdown-menu li:first').removeClass('active');
   });

   $('.form-control').on('input',function(e){
     $('ul.dropdown-menu li:first').removeClass('active');
   });
});
即使在搜索查询中使用backspace键,这也能很好地工作


否,当我删除“多个”时,它会再次显示活动的第一个li,因此您只需从
show.bs中删除该类。也选择
事件类型。就这样。更新了答案。你在哪里更新的??你能和我分享一下JSFIDLE吗?你做了一个很好的尝试,但是第一个li从未被选中。。所以它也必须是动态的:(是的,很遗憾,这就是这个库的局限性:(您甚至可以尝试使用
one()
方法,但我相信即使这样,您也不会想要。
$(function() {
   //This event is fired when the dropdown has been made visible to the user
   $('.selectpicker').on('shown.bs.select', function (e) {
     $('ul.dropdown-menu li:first').removeClass('active');
   });

   $('.form-control').on('input',function(e){
     $('ul.dropdown-menu li:first').removeClass('active');
   });
});