如果我在选项中添加了一个类,则一旦使用Selectize,它将被删除。
例如
HTML
<select>
<option value="" class="test"></option>
</select>
Js
$('select').selectize({
sortField: 'text'
})
这将删除我的原始班级(测试),并仅替换为selectize类。有什么线索可以保留吗?
答案 0 :(得分:1)
只需将copyClassesToDropdown
添加到true
作为参考,请参考此link
$('select').selectize({
sortField: 'text',
copyClassesToDropdown: true
})
下面的代码段供您参考。
.pokemon{
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3/highlight.min.js"></script>
<script src="https://selectize.github.io/selectize.js/js/selectize.js"></script>
<script src="https://selectize.github.io/selectize.js/js/main.js"></script>
<script src="https://platform.twitter.com/js/button.93a0c25c2d2f3081c705c98c2d9dec0e.js"></script>
<div class="demo">
<h2><select></h2>
<div class="control-group">
<label for="select-beast">Beast:</label>
<select id="select-beast" class="demo-default" placeholder="Select a person...">
<option value="" class="pokemon">Select a person...</option>
<option value="4">Thomas Edison</option>
<option value="1" class="pokemon">Nikola</option>
<option value="3" class="pokemon">Nikola Tesla</option>
<option value="5" class="pokemon">Arnold Schwarzenegger</option>
</select>
</div>
<script>
$('#select-beast').selectize({
create: true,
copyClassesToDropdown: true
sortField: {
field: 'text',
direction: 'asc'
},
dropdownParent: 'body'
});
</script>
</div>