支持自动完成 Easy Tags Manager小工具 标记它

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

简介

标记它是一个轻量级的jQuery插件,用于将普通HTML列表转换为标记管理器,允许与任何输入字段通信,并支持自动完成/建议(需要jQuery UI)。

参见:

  • jQuery和Vanilla JavaScript中的10个最佳标签输入插件

如何使用它:

1.在html页面上加载jQuery库和jQuery标记it插件的文件。

  1. <!-- jQuery is required -->
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3.  
  4. <!-- jQuery Tag-It Plugin -->
  5. <link href="css/jquery.tagit.css" rel="stylesheet" />
  6. <script src="js/tag-it.min.js"></script>

2.该插件需要jQuery UI库来实现自动完成功能。

  1. <script src="/path/to/cdn/jquery-ui.min.js"></script>

3.标签管理器的基本HTML结构。

  1. <form>
  2. <input name="tags" id="demo-input" value="Armenia, Germany" disabled="true">
  3. <ul id="demo-list"></ul>
  4. <input type="submit" value="Submit">
  5. </form>

4.为标签管理器创建一个建议值的数组。

  1. var country_list = ["Afghanistan","Albania","Algeria"];

5.使用一些选项初始化标签管理器。

  1. $('#demo-list').tagit({
  2. availableTags: country_list,
  3. // This will make Tag-it submit a single form value, as a comma-delimited field.
  4. singleField: true,
  5. singleFieldNode: $('#demo-input')
  6. });

6.更多具有默认值的配置选项。

  1. $('#demo-list').tagit({
  2.  
  3. allowDuplicates: false,
  4. caseSensitive: true,
  5. fieldName: "tags",
  6. placeholderText: null,
  7. readOnly: false,
  8.  
  9. // Require confirmation to remove tags
  10. removeConfirmation: false,
  11.  
  12. // Max number of tags allowed (null for unlimited)
  13. tagLimit: null,
  14.  
  15. // Used for autocomplete
  16. availableTags: [],
  17.  
  18. // Use to override or add any options to the autocomplete widget
  19. autocomplete: {},
  20.  
  21. // Shows autocomplete before the user even types anything
  22. showAutocompleteOnFocus: false,
  23.  
  24. // When enabled, quotes are unneccesary for inputting multi-word tags
  25. allowSpaces: false,
  26.  
  27. // Use a single hidden field for the form, rather than one per tag.
  28. // It will delimit tags in the field with singleFieldDelimiter.
  29. singleField: false,
  30. singleFieldDelimiter: ",",
  31.  
  32. // Set this to an input DOM node to use an existing form field.
  33. singleFieldNode: null,
  34.  
  35. // Whether to animate tag removals or not
  36. animate: true,
  37.  
  38. // Optionally set a tabindex attribute on the input that gets
  39. tabIndex: null,
  40. });

7.提供回调功能。

  1. $('#demo-list').tagit({
  2. beforeTagAdded: null,
  3. afterTagAdded: null,
  4. beforeTagRemoved: null,
  5. afterTagRemoved: null,
  6. onTagClicked: null,
  7. onTagLimitExceeded: null,
  8. });

8.API方法。

  1. // Returns an array of the text values of all the tags
  2. $("#demo-list").tagit("assignedTags");
  3.  
  4. // Adds new tag
  5. $("#demo-list").createTag(tagLabel, additionalClass);
  6.  
  7. // Called before tag is created
  8. $("#demo-list").preprocessTag(function, Callback);
  9.  
  10. // Finds the tag with the label tagLabel and removes it.
  11. $("#demo-list").removeTagByLabel(tagLabel, animate);
  12.  
  13. // removes all tags
  14. $("#demo-list").tagit("removeAll");

更新日志:

2022-10-25

  • 错误修复

预览截图