selectize.js select 下拉显示默认打开

selectize.js select dropdown show by default opened

我正在使用 selectize.js 作为我的搜索表单,并希望显示默认打开的 select 列表。

<select id="select-state" name="state[]" multiple class="demo-default" placeholder="Select Models">
 <option value="">Select Models</option>
 <option value="Tanzania">Tanzania</option>
 <option value="Kenya">Kenya</option>
 <option value="Uganda">Uganda</option>
 <option value="Asia">Asia</option>
 <option value="Malaysia">Malaysia</option>
 <option value="Japan">Japan</option>
</select>
<script>
$('#select-state').selectize({
    maxItems: 5
});
</script>

我尝试了不同的方法,但其中 none 有效。 通过 jQuery

$('#select-state').show().focus().click();

来自 CSS

<style>.selectize-dropdown{ display:block!important; visibility:visible!important;}</style>

试试这个:

var select = $('#select-state').selectize({
  maxItems: 5
});
var selectize = select[0].selectize;
selectize.open();
<link href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.js"></script>

<select id="select-state" name="state[]" multiple class="demo-default" placeholder="Select Models">
  <option value="">Select Models</option>
  <option value="Tanzania">Tanzania</option>
  <option value="Kenya">Kenya</option>
  <option value="Uganda">Uganda</option>
  <option value="Asia">Asia</option>
  <option value="Malaysia">Malaysia</option>
  <option value="Japan">Japan</option>
</select>