一个jQuery插件,它将普通的选择框转换为用户友好的可过滤多选下拉列表,用户可以通过选中复选框来选择一个或多个选项。
根据LGPL-2.1许可证进行许可。
1.在文档中加载jQuery库(必需)和Bootstrap的样式表(可选但推荐)。
<link rel="stylesheet" href="filter_multi_select.css" /> <script src="filter-multi-select-bundle.min.js"></script>
2.在文档中加载过滤器多选插件的JavaScript和样式表。
<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" /> <script src="/path/to/cdn/jquery.slim.min.js"></script>
3.通过简单地附加函数来创建一个基本的可筛选多选下拉列表过滤器多选
到现有的选择框,并使用倍数
属性:
<select multiple name="language" id="languages"> <option value="js">JavaScript</option> <option value="html">HTML</option> <option value="css">CSS</option> ... more options here ... </select>
const languages = $('#languages').filterMultiSelect();
4.您也可以通过JavaScript将选项添加到多选下拉列表中。
const languages = $('#languages').filterMultiSelect({ items: [ ["Ruby","r"], ["C++","c",false,true] ], });
5.可用于自定义多选下拉列表的选项。
const languages = $('#languages').filterMultiSelect({ // displayed when no options are selected placeholderText: "nothing selected" // placeholder for search field filterText: "Filter" // Select All text selectAllText: "Select All", // Label text labelText: "", // the number of items able to be selected // 0 means no limit selectionLimit: 0, // determine if is case sensitive caseSensitive: false, // allows the user to disable and enable options programmatically allowEnablingAndDisabling: true, });
6.API方法。
// check is has an option languages.hasOption(value); // select/deselect an option languages.selectOption(value:string); languages.deselectOption(value:string); // check if an option is selected languages.isOptionSelected(value:string); // select/deselect all non-disabled options languages.selectAll(); languages.deselectAll(); // enable/disable an option languages.enableOption(value:string); languages.disableOption(value:string); // check if an option is disabled languages.isOptionDisabled(value:string); // enable/disable the multiselect dropdown languages.enable(); languages.disable(); // returns a JSON string of the selected options' values languages.getSelectedOptionsAsJson(includeDisabled=true);
v1.4.1 (2022-06-16)
v1.4.0 (2022-06-15)
v1.3.0 (2022-06-01)
v1.12 (2022-02-27)
v1.1.0 (2021-03-11)
作者:安德鲁
网站:https://github.com/andreww1011/filter-multi-select