如何使用jquery和selectize.js在下拉列表中点击所有项目时选择所有项目?

问题描述 投票:0回答:1

我遇到了一个问题,就是当我点击下拉列表中的所有项目时,如何显示所有项目。基本上,我使用了 https:/harvesthq.github.iochosen。. 我只是希望当用户点击下拉列表中的所有选项时,下拉列表中的所有项目应该显示在mutliselect框中,而不是像图片中显示的所有选项。谁能帮帮我。谢谢你的帮助。enter image description here

html 

<select data-placeholder="Type here to find device" id="logs"  name="tags[]"  multiple class="chosen-select form-control" onchange="checkLogging()" required>
<option value="" selected></option>
<option value="ALL">All</option>
<option value="ASA" >Cisco ASA</option>
<option value="ISE"> CISCO ISE</option>
<option value="MS">Microsoft Windows</option>
<option value="ATA">Microsoft ATA</option>
<option value="Alliance">SWIFT Alliance</option>
<option value="Proxy">Bluecoat Proxy</option>
<option value="Csp"> Symantec CSP</option>
</select> 

js

$(function() {
    var filter = $('#logs');
    filter.on('change', function() {
      if (this.selectedIndex) return; //not `Select All`
      filter.find('option:gt(0)').prop('selected', true);
      filter.find('option').eq(0).prop('selected', false);
    });
  });
jquery multi-select selectize.js
1个回答
0
投票

你可以这样做。

$(function() {
   var filter = $('#logs');
   filter.on('change', function() {
      if ($(this).val() == ",ALL") {
         filter.val('').trigger('chosen:updated');
         filter.find('option:not([value="ALL"])').attr('selected', 'selected');
         filter.trigger('chosen:updated');
      }
   });
});

工作 小提琴.

© www.soinside.com 2019 - 2024. All rights reserved.