jquery.multi-select.js 是一款 jQuery 多选下拉框插件。该插件可以将 select 元素转换为带 checkbox 的多选下拉框,非常实用。
在页面中引入下面的文件。
<link rel="stylesheet" type="text/css" href="./src/example-styles.css">
<script src="js/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="./src/jquery.multi-select.js"></script>
<select id="languages" name="languages" multiple>
<option value="JavaScript">JavaScript</option>
<option value="C++">C++</option>
<option value="Python">Python</option>
<option value="Ruby">Ruby</option>
<option value="PHP">PHP</option>
<option value="Pascal">Pascall</option>
</select>
$('#languages').multiSelect();
.multi-select-container {
display: inline-block;
position: relative;
}
.multi-select-menu {
position: absolute;
left: 0;
top: 0.8em;
float: left;
min-width: 100%;
background: #fff;
margin: 1em 0;
padding: 0.4em 0;
border: 1px solid #aaa;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
display: none;
}
.multi-select-menu input {
margin-right: 0.3em;
vertical-align: 0.1em;
}
.multi-select-button {
display: inline-block;
font-size: 0.875em;
padding: 0.2em 0.6em;
max-width: 20em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: -0.5em;
background-color: #fff;
border: 1px solid #aaa;
border-radius: 4px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
cursor: default;
}
.multi-select-button:after {
content: "";
display: inline-block;
width: 0;
height: 0;
border-style: solid;
border-width: 0.4em 0.4em 0 0.4em;
border-color: #999 transparent transparent transparent;
margin-left: 0.4em;
vertical-align: 0.1em;
}
.multi-select-container--open .multi-select-menu { display: block; }
.multi-select-container--open .multi-select-button:after {
border-width: 0 0.4em 0.4em 0.4em;
border-color: transparent transparent #999 transparent;
}
$('#languages').multiSelect({
// 自定义HTML模板
'containerHTML': 'lt;div class="multi-select-container"gt;',
'menuHTML': 'lt;div class="multi-select-menu"gt;',
'buttonHTML': 'lt;span class="multi-select-button"gt;',
'menuItemsHTML': 'lt;div class="multi-select-menuitems"gt;',
'menuItemHTML': 'lt;label class="multi-select-menuitem"gt;',
'presetsHTML': 'lt;div class="multi-select-presets"gt;',
// sets some HTML (eg: lt;div class="multi-select-modal"gt;) to enable the modal overlay.
'modalHTML': undefined,
// Active CSS class
'activeClass': 'multi-select-container--open',
// Text to show when no option is selected
'noneText': '-- Select --',
// Text to show when all options are selected
'allText': undefined,
// an array of preset option groups
'presets': undefined,
// CSS class added to the container, when the menu is about to extend beyond the right edge of the position Menu Within element
'positionedMenuClass': 'multi-select-container--positioned',
// If you provide a jQuery object here, the plugin will add a class (see positionedMenuClass option) to the container when the right edge of the dropdown menu is about to extend outside the specified element, giving you the opportunity to use CSS to prevent the menu extending, for example, by allowing the option labels to wrap onto multiple lines.
'positionMenuWithin': undefined,
// The plugin will attempt to keep this distance, in pixels, clear between the bottom of the menu and the bottom of the viewport, by setting a fixed height style if the menu would otherwise approach this distance from the bottom edge of the viewport.
'viewportBottomGutter': 20,
// minimal height
'menuMinHeight': 200
});
Github 网址:https://github.com/mysociety/jquery-multi-select
演示地址 | 下载地址 |
专业提供WordPress主题安装、深度汉化、加速优化等各类网站建设服务,详询在线客服!