首先引入jQuery
,然后引入selectize
库,包括CSS和JS, 即:和selectize.default.css
和selectize.min.js
,示例如下:
<link rel="stylesheet" href="js/selectize/css/selectize.default.css">
<script src="js/jquery.min.js"></script>
<script src="js/selectize/js/standalone/selectize.js"></script>
<div class="control-group">
<label for="select-beast">Beast:</label>
<select id="select-beast" class="demo-default" placeholder="Select a person...">
<option value="">Select a person...</option>
<option value="4">Thomas Edison</option>
<option value="1">Nikola</option>
<option value="3">Nikola Tesla</option>
<option value="5">Arnold Schwarzenegger</option>
</select>
</div>
<script>
$('#select-beast').selectize({
create: true, //允许增加下拉选项,输入后按回车即可
sortField: { //可排序字段
field: 'text',
direction: 'asc'
},
dropdownParent: 'body'
});
</script>
源码地址:https://github.com/selectize/selectize.js
API 文档:https://github.com/selectize/selectize.js/blob/master/docs/api.md
配置文档:https://github.com/selectize/selectize.js/blob/master/docs/usage.md
事件文档:https://github.com/selectize/selectize.js/blob/master/docs/events.md
自定义插件文档:https://github.com/selectize/selectize.js/blob/master/docs/plugins.md
the end