响应式可访问自定义选择下拉插件 jQuery ikSelect

  • 源码大小:46.5KB
  • 所需积分:1积分
  • 源码编号:19JP-3393
  • 浏览次数:603次
  • 最后更新:2023年06月08日
  • 所属栏目:表单
本站默认解压密码:19jp.com 或 19jp_com

简介

ikSelect是一个简单、快速、响应迅速、可访问的自定义选择下拉jQuery插件,可以使用自己的CSS进行完全样式化。

更多功能:

  • 实时搜索。
  • 支持选项组。
  • 使用本机select元素。
  • 移动友好型。
  • 动态添加/删除选项和选项组。
  • 强大的API。

参见:

  • 替换Native Select Box的10个最佳下拉插件

目录:

  • 初始化
  • 可进入样式表对话框
  • 选项
  • API方法
  • 事件

如何使用它:

1.在jQuery之后下载并加载ikSelect插件的脚本。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/src/jquery.ikSelect.js"></script>

2.将插件附加到现有的选择要素

  1. <select>
  2. <optgroup label="Seven Wonders of the Ancient World">
  3. <option>Great Pyramid of Giza</option>
  4. <option>Hanging Gardens of Babylon</option>
  5. <option>Statue of Zeus at Olympia</option>
  6. <option>Temple of Artemis at Ephesus</option>
  7. <option>Mausoleum at Halicarnassus</option>
  8. <option>Colossus of Rhodes</option>
  9. <option>Lighthouse of Alexandria</option>
  10. </optgroup>
  11. <optgroup label="Seven Natural Wonders of the World">
  12. <option>Grand Canyon</option>
  13. <option>Great Barrier Reef</option>
  14. <option>Harbor of Rio de Janeiro</option>
  15. <option>Mount Everest</option>
  16. <option>Aurora</option>
  17. <option>Parícutin volcano</option>
  18. <option>Victoria Falls</option>
  19. </optgroup>
  20. </select>
  1. $(function () {
  2. $('select').ikSelect();
  3. });

3.将您自己的样式应用于自定义选择下拉列表。

  1. .ik_select {
  2. /*
  3. Your Styles Here
  4. */
  5. }
  6.  
  7. .ik_select_link {
  8. /*
  9. Your Styles Here
  10. */
  11. }
  12.  
  13. .ik_select_link_focus {
  14. /*
  15. Your Styles Here
  16. */
  17. }
  18.  
  19. .ik_select_link_disabled {
  20. /*
  21. Your Styles Here
  22. */
  23. }
  24.  
  25. .ik_select_link_text {
  26. /*
  27. Your Styles Here
  28. */
  29. }
  30.  
  31. .ik_select_dropdown {
  32. /*
  33. Your Styles Here
  34. */
  35. }
  36.  
  37. .ik_select_list {
  38. /*
  39. Your Styles Here
  40. */
  41. }
  42.  
  43. .ik_select_optgroup {
  44. /*
  45. Your Styles Here
  46. */
  47. }
  48.  
  49. .ik_select_optgroup_label {
  50. /*
  51. Your Styles Here
  52. */
  53. }
  54.  
  55. .ik_select_option {
  56. /*
  57. Your Styles Here
  58. */
  59. }
  60.  
  61. .ik_select_option_label {
  62. /*
  63. Your Styles Here
  64. */
  65. }
  66.  
  67. .ik_select_hover {
  68. /*
  69. Your Styles Here
  70. */
  71. }
  72.  
  73. .ik_select_active {
  74. /*
  75. Your Styles Here
  76. */
  77. }
  78.  
  79. .ik_select_filter_wrap {
  80. /*
  81. Your Styles Here
  82. */
  83. }
  84.  
  85. .ik_select_filter {
  86. /*
  87. Your Styles Here
  88. */
  89. }
  90.  
  91. .ik_nothing_found {
  92. /*
  93. Your Styles Here
  94. */
  95. }

4.自定义选择下拉菜单。

  1. $('select').ikSelect({
  2.  
  3. // custom template
  4. syntax: '<div class="ik_select_link"><div class="ik_select_link_text"></div></div><div class="ik_select_dropdown"><div class="ik_select_list"></div></div>',
  5.  
  6. // auto set the width of the select according to the longest option
  7. autoWidth: true,
  8.  
  9. // auto set the width of the dropdown according to the longest option
  10. ddFullWidth: true,
  11.  
  12. // include scrollbar width or not
  13. equalWidths: true,
  14.  
  15. // change the width of the select according to it's content
  16. dynamicWidth: false,
  17.  
  18. // move the select t the body when it is clicked along with the dropdown
  19. extractLink: false,
  20.  
  21. // additional CSS classes
  22. customClass: '',
  23.  
  24. // additional CSS classes for links
  25. linkCustomClass: '',
  26.  
  27. // additional CSS classes for the dropdown
  28. ddCustomClass: '',
  29.  
  30. // max height of the dropdown
  31. ddMaxHeight: 200,
  32.  
  33. // extra width
  34. extraWidth: 0,
  35.  
  36. // enable live search
  37. filter: false,
  38. nothingFoundText: 'Nothing found',
  39.  
  40. // is disabled or not
  41. isDisabled: false,
  42.  
  43. });

5.您也可以通过HTML数据-*属性传递选项:

  1. <select data-autowidth="true" data-customclass="someclass">
  2. ...
  3. </select>

6.API方法。

  1. // override defaults
  2. $.ikSelect.extendDefaults(settings);
  3.  
  4. // reset
  5. $(selector).ikSelect('reset');
  6.  
  7. // re-redner
  8. $(selector).ikSelect('redraw');
  9.  
  10. // add options
  11. $(selector).ikSelect('addOptions', optionObject[, optionIndex, optgroupIndex]);
  12. // or
  13. $(selector).ikSelect('addOptions', optionObjectsArray[, optionIndex, optgroupIndex]);
  14.  
  15. // add option groups
  16. $(selector).ikSelect('addOptgroups', optgroupObject[, optgroupIndex]);
  17. // or
  18. $(selector).ikSelect('addOptgroups', optgroupObjectsArray[, optgroupIndex]);
  19.  
  20. // remove options
  21. $(selector).ikSelect('removeOptions', optionIndex[, optgroupIndex]);
  22. $(selector).ikSelect('removeOptions', optionIndexesArray[, optgroupIndex]);
  23.  
  24. // remove option groups
  25. $(selector).ikSelect('removeOptgroups', optgroupIndex);
  26. // or
  27. $(selector).ikSelect('removeOptgroups', optgroupIndexesArray);
  28.  
  29. // select an option
  30. $(selector).ikSelect('select', optionValue[, isIndex]);
  31.  
  32. // show the dropdown
  33. $(selector).ikSelect('showDropdown');
  34.  
  35. // hide the dropdown
  36. $(selector).ikSelect('hideDropdown');
  37.  
  38. // disable the select
  39. $(selector).ikSelect('disable');
  40.  
  41. // enable the select
  42. $(selector).ikSelect('enable');
  43.  
  44. // toggle the select
  45. $(selector).ikSelect('toggle'[, enableOrDisable]);
  46.  
  47. // disable options
  48. $(selector).ikSelect('disableOptions', optionIndexOrValue[, isIndex]);
  49. // or
  50. $(selector).ikSelect('disableOptions', optionIndexesOrValuesArray[, isIndex]);
  51.  
  52. // enable options
  53. $(selector).ikSelect('enableOptions', optionIndexOrValue[, isIndex]);
  54. // or
  55. $(selector).ikSelect('enableOptions', optionIndexesOrValuesArray[, isIndex]);
  56.  
  57. // toggle options
  58. $(selector).ikSelect('toggleOptions', optionIndexOrValue[, isIndex, enableOrDisable]);
  59. $(selector).ikSelect('toggleOptions', optionIndexesOrValuesArray[, isIndex, enableOrDisable]);
  60.  
  61. // disable option groups
  62. $(selector).ikSelect('disableOptgroups', optgroupIndex);
  63. // or
  64. $(selector).ikSelect('disableOptgroups', optgroupIndexesArray);
  65.  
  66. // enable option groups
  67. $(selector).ikSelect('enableOptgroups', optgroupIndex);
  68. // or
  69. $(selector).ikSelect('enableOptgroups', optgroupIndexesArray);
  70.  
  71. // toggle option groups
  72. $(selector).ikSelect('toggleOptgroups', optgroupIndex[, enableOrDisable]);
  73. // or
  74. $(selector).ikSelect('toggleOptgroups', optgroupIndexesArray[, enableOrDisable]);
  75.  
  76. // destroy
  77. $(selector).ikSelect('detach');

7.回调函数。

  1. $('select').ikSelect({
  2. onInit: function() {},
  3. onShow: function () {},
  4. onHide: function () {},
  5. onKeyUp: function () {},
  6. onKeyDown: function () {},
  7. onHoverMove: function () {}
  8. });

预览截图