jQuery插件 复选框 多选列表 多选

  • 源码大小:19.76KB
  • 所需积分:1积分
  • 源码编号:19JP-3160
  • 浏览次数:666次
  • 最后更新:2023年05月12日
  • 所属栏目:表单
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

MultiSelect是一个jQuery插件,它将普通的多选列表转换为带有复选框的多列下拉列表。

查看更多多选插件,网址:

  • 最佳多选jQuery插件

安装:

  1. # NPM
  2. $ npm install jQuery-MultiSelect --save
  3.  
  4. # Bower
  5. $ bower install jQuery-MultiSelect

如何使用它:

1.在html页面中包含jQuery库和jQuery多选插件的文件。

  1. <script src="jquery.min.js"></script>
  2. <script src="jquery.multiselect.js"></script>

2.调用上的插件倍数选择元素。

  1. $('select[multiple]').multiselect({
  2. /* OPTIONS */
  3. });

3.可用选项。

  1. $('select[multiple]').multiselect({
  2.  
  3. columns: 1, // how many columns should be use to show options
  4. search : false, // include option search box
  5.  
  6. // search filter options
  7. searchOptions : {
  8. delay : 250, // time (in ms) between keystrokes until search happens
  9. showOptGroups: false, // show option group titles if no options remaining
  10. searchText : true, // search within the text
  11. searchValue : false, // search within the value
  12. onSearch : function( element ){} // fires on keyup before search on options happens
  13. },
  14.  
  15. // plugin texts
  16. texts: {
  17. placeholder : 'Select options', // text to use in dummy input
  18. search : 'Search', // search input placeholder text
  19. selectedOptions: ' selected', // selected suffix text
  20. selectAll : 'Select all', // select all text
  21. unselectAll : 'Unselect all', // unselect all text
  22. noneSelected : 'None Selected' // None selected text
  23. },
  24.  
  25. // general options
  26. selectAll : false, // add select all option
  27. selectGroup : false, // select entire optgroup
  28. minHeight : 200, // minimum height of option overlay
  29. maxHeight : null, // maximum height of option overlay
  30. maxWidth : null, // maximum width of option overlay (or selector)
  31. maxPlaceholderWidth: null, // maximum width of placeholder button
  32. maxPlaceholderOpts : 10, // maximum number of placeholder options to show until "# selected" shown instead
  33. showCheckbox : true, // display the checkbox to the user
  34. optionAttributes : [], // attributes to copy to the checkbox from the option element
  35.  
  36. // Callbacks
  37. onLoad : function( element ){}, // fires at end of list initialization
  38. onOptionClick : function( element, option ){}, // fires when an option is clicked
  39. onControlOpen : function( element ){}, // fires when the options list is opened
  40. onControlClose: function( element ){}, // fires when the options list is closed
  41. onSelectAll : function( element, selected ){}, // fires when (un)select all is clicked
  42. onPlaceholder : function( element, placeholder, selectedOpts ){}, // fires when the placeholder txt is updated
  43.  
  44. // @NOTE: these are for future development
  45. minSelect: false, // minimum number of items that can be selected
  46. maxSelect: false, // maximum number of items that can be selected
  47.  
  48. });

4.API方法。

  1. // loadOptions( options, overwrite, updateSelect )
  2. $('select[multiple]').multiselect( 'loadOptions', [{
  3. name : 'Option Name 1',
  4. value : 'option-value-1',
  5. checked: false
  6. },{
  7. name : 'Option Name 2',
  8. value : 'option-value-2',
  9. checked: false
  10. }]);
  11.  
  12. // updates settings
  13. $('select[multiple]').multiselect( 'settings', { columns: 2 });
  14.  
  15. // disables the plugin
  16. $('select[multiple]').multiselect( 'unload' );
  17.  
  18. // reloads the plugin
  19. $('select[multiple]').multiselect( 'reload' );
  20.  
  21. // resets the plugin
  22. $('select[multiple]').multiselect( 'reset' );
  23.  
  24. // enables/disables
  25. $('select[multiple]').multiselect( 'disable', true ); $('select[multiple]').multiselect( 'disable', false );

更新日志:

v2.4.22 (2023-03-03)

  • 使现代化

v2.4.21版本(2022-03-16)

  • add-onControlOpen回调

v2.4.20 (2021-12-08)

  • 优化的下拉位置行为

v2.4.19版本(2020-06-27)

  • 修正:如果列表包含禁用选项,则选择所有禁用选项,并将其计入选择。

v2.4.18版本(2020-01-29)

  • 允许在<option>中使用HTML

v2.4.17版本(2019-10-16)

  • 添加了onPlaceholder回调

v2.4.16版本(2019-01-19)

  • 固定了放置在jquery选择器中时的转义选项值。如果值有反斜杠,这将解决多选的问题。

v2.4.15(2018年8月18日)

  • rem已弃用$.bind到$.on,删除未使用的opts,从prev/next切换

v2.4.14版本(2018-07-18)

  • 修正:占位符在某些项目中不起作用

v2.4.13版本(2018-07-08)

  • 使用<select>元素的情况下的代码调整/优化

v2.4.12(2018年5月23日)

  • 修复了页面加载时的select/uninstall问题

v2.4.11(2018年03月07日)

  • 修正了:OnSelectAll方法没有指定是选择还是取消选择

v2.4.10(2018年2月17日)

  • 性能增强

v2.4.9版本(2018-01-19)

  • 表单提交时未输入

v2.4.8版本(2018年01月09日)

  • 添加了SelectAll功能

v2.4.7版本(2017-12-01)

  • 已修复:updatePlaceholderText问题

v2.4.6版本(2017-11-10)

  • 在初始化期间添加对select元素上多个属性的检查

v2.4.5版本(2017-11-08)

  • 修正:不显示禁用的默认选择值

v2.4.4版本(2017-11-01)

  • 更多键盘导航支持
  • 将ms活动类移动到ms选项包装,用于目标定位
  • 添加的ms在有选择的选项时有选择

2017-10-14

  • v2.4.3:从(取消)全选中排除禁用选项

2017-09-08

  • v2.4.2版本:更新的文档

2017-08-05

  • v2.4.1:修复maxWidth选项的问题。

2017-07-22

  • v2.4:修复搜索和(取消)选择所有不工作的功能的问题

2017-06-17

  • v2.3.13:修复禁用方法问题,使用hasClass()调用修复错误

2017-06-03

  • 性能优化

2016-03-11

  • 错误修复。

2016-01-15

  • 错误修复。

2015-12-11

  • 错误修复。

2015-11-20

  • 新建搜索并选择所有选项,默认占位符文本

2015-11-19

  • JS更新
  • 错误修复

2015-06-12

  • 错误修复

2015-06-11

  • 触摸设备滚动错误修复

2015-06-10

  • 浏览器错误修复(主要是safari)

预览截图