表单/表格

jQuery多选下拉框插件

阿里云


jquery.multi-select.js 是一款 jQuery 多选下拉框插件。该插件可以将 select 元素转换为带 checkbox 的多选下拉框,非常实用。

使用方法

在页面中引入下面的文件。

也想出现在这里?联系我们
创客主机
  1. <link rel="stylesheet" type="text/css" href="./src/example-styles.css">
  2. <script src="js/jquery.min.js" type="text/javascript"></script>
  3. <script type="text/javascript" src="./src/jquery.multi-select.js"></script>

HTML 结构

  1. <select id="languages" name="languages" multiple>
  2. <option value="JavaScript">JavaScript</option>
  3. <option value="C++">C++</option>
  4. <option value="Python">Python</option>
  5. <option value="Ruby">Ruby</option>
  6. <option value="PHP">PHP</option>
  7. <option value="Pascal">Pascall</option>
  8. </select>

初始化插件

  1. $('#languages').multiSelect();

CSS 样式

  1. .multi-select-container {
  2.   display: inline-block;
  3.   position: relative;
  4. }
  5.  
  6. .multi-select-menu {
  7.   position: absolute;
  8.   left: 0;
  9.   top: 0.8em;
  10.   float: left;
  11.   min-width: 100%;
  12.   background: #fff;
  13.   margin: 1em 0;
  14.   padding: 0.4em 0;
  15.   border: 1px solid #aaa;
  16.   box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  17.   display: none;
  18. }
  19.  
  20. .multi-select-menu input {
  21.   margin-right: 0.3em;
  22.   vertical-align: 0.1em;
  23. }
  24.  
  25. .multi-select-button {
  26.   display: inline-block;
  27.   font-size: 0.875em;
  28.   padding: 0.2em 0.6em;
  29.   max-width: 20em;
  30.   white-space: nowrap;
  31.   overflow: hidden;
  32.   text-overflow: ellipsis;
  33.   vertical-align: -0.5em;
  34.   background-color: #fff;
  35.   border: 1px solid #aaa;
  36.   border-radius: 4px;
  37.   box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  38.   cursor: default;
  39. }
  40.  
  41. .multi-select-button:after {
  42.   content: "";
  43.   display: inline-block;
  44.   width: 0;
  45.   height: 0;
  46.   border-style: solid;
  47.   border-width: 0.4em 0.4em 0 0.4em;
  48.   border-color: #999 transparent transparent transparent;
  49.   margin-left: 0.4em;
  50.   vertical-align: 0.1em;
  51. }
  52.  
  53. .multi-select-container--open .multi-select-menu { display: block; }
  54.  
  55. .multi-select-container--open .multi-select-button:after {
  56.   border-width: 0 0.4em 0.4em 0.4em;
  57.   border-color: transparent transparent #999 transparent;
  58. }

配置参数

  1. $('#languages').multiSelect({
  2.  
  3.   // 自定义HTML模板
  4.   'containerHTML': 'lt;div class="multi-select-container"gt;',
  5.   'menuHTML': 'lt;div class="multi-select-menu"gt;',
  6.   'buttonHTML': 'lt;span class="multi-select-button"gt;',
  7.   'menuItemsHTML': 'lt;div class="multi-select-menuitems"gt;',
  8.   'menuItemHTML': 'lt;label class="multi-select-menuitem"gt;',
  9.   'presetsHTML': 'lt;div class="multi-select-presets"gt;',
  10.  
  11.   // sets some HTML (eg: lt;div class="multi-select-modal"gt;) to enable the modal overlay.
  12.   'modalHTML': undefined,
  13.  
  14.   // Active CSS class
  15.   'activeClass': 'multi-select-container--open',
  16.  
  17.   // Text to show when no option is selected
  18.   'noneText': '-- Select --',
  19.  
  20.   // Text to show when all options are selected
  21.   'allText': undefined,
  22.  
  23.   // an array of preset option groups
  24.   'presets': undefined,
  25.  
  26.   // CSS class added to the container, when the menu is about to extend beyond the right edge of the position Menu Within element
  27.   'positionedMenuClass': 'multi-select-container--positioned',
  28.  
  29.   // 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.
  30.   'positionMenuWithin': undefined,
  31.  
  32.   // 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.
  33.   'viewportBottomGutter': 20,
  34.  
  35.   // minimal height
  36.   'menuMinHeight': 200
  37.  
  38. });

Github 网址:https://github.com/mysociety/jquery-multi-select

jQuery 多选下拉框插件

已有 498 人购买
  • 9zud
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(2)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!