自动完成功能 用户友好时间选择器 jQuery时间自动完成

  • 源码大小:94.05KB
  • 所需积分:1积分
  • 源码编号:19JP-3540
  • 浏览次数:712次
  • 最后更新:2023年06月24日
  • 所属栏目:时间和时钟
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

使用JavaScript时间选择器可以更好地控制用户输入的时间输入。

秒、分钟还是小时?有了这个用户友好的时间选择器jQuery插件,访问者将能够在自定义步骤中选择一个小时以及分钟和秒。自动完成功能将建议与之前输入的值最匹配。

如何使用它:

1.在页面上包括必要的jQuery库和jQuery UI的自动完成小部件。

  1. <link rel="stylesheet" href="/path/to/cdn/jquery-ui.min.css" />
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3. <script src="/path/to/cdn/jquery-ui.min.js"></script>

2.加载jQuery timeAutocomplete插件的文件。

  1. <!-- Core -->
  2. <script src="./src/jquery.timeAutocomplete.js"></script>
  3.  
  4. <!-- AM/PM extension -->
  5. <script src="./src/formatters/ampm.js"></script>
  6.  
  7. <!-- 24hr extension -->
  8. <script src="./src/formatters/24hr.js"></script>
  9.  
  10. <!-- French time format extension -->
  11. <script src="./src/formatters/french.js"></script>

3.将时间选择器连接到输入字段。就是这样。

  1. <input type="text" id="example" />
  1. $('#example').timeAutocomplete({
  2. // options here
  3. });

4.使用启动小时结束小时选项。

  1. $('#example').timeAutocomplete({
  2. start_hour: 0,
  3. end_hour: 24,
  4. });

5.创建一个智能时间范围选择器。我们使用来自选择器“到”字段上的一组选项中的选项。这使得时间自动完成能够意识到其他字段中的时间。如果“from”字段为“8:00 AM”,并且我们开始在“to”字段中键入“4”,它将显示4个“PM”选项的列表,而不是4个“AM”选项。

  1. <input type="text" id="from-ampm" />
  2. <input type="text" id="to-ampm" />
  1. $('#from-ampm').timeAutocomplete({
  2. increment: 5,
  3. value: '08:00:00'
  4. });
  5.  
  6. $('#to-ampm').timeAutocomplete({
  7. increment: 5,
  8. from_selector: '#from-ampm',
  9. value: '17:30:00'
  10. });

6.指定您希望时间下拉列表出现的增量(5、10、15、30、60)。15分钟的增量将产生:[上午7:15,上午7:30,上午7:45]。

  1. $('#example').timeAutocomplete({
  2. increment: 5
  3. });

7.设置要使用的时间格式化程序:ampm、24hr或french。

  1. $('#example').timeAutocomplete({
  2. formatter: '24hr',
  3. });

8.更多插件选项。

  1. $('#example').timeAutocomplete({
  2.  
  3. // jQuery UI Autocomplete Options
  4. auto_complete: {
  5. delay: 0,
  6. autoFocus: true,
  7. minLength: 0
  8. },
  9.  
  10. // injects the current time as a value
  11. auto_value: true,
  12.  
  13. // populates the time field with the default value
  14. blur_empty_populate: true,
  15.  
  16. // allows you to pass in a 24hr (H:i:s) time to be formatted and displayed in the field.
  17. value: '',
  18.  
  19. // AM/PM text
  20. pm_text: 'PM',
  21. am_text: 'AM',
  22.  
  23. // over-ride if not using built-in populator
  24. times: [],
  25.  
  26. // the default empty value
  27. empty: {
  28. h: '12',
  29. m: '00',
  30. sep: ':',
  31. postfix: ' PM'
  32. }
  33. });

9.API方法。

  1. $('#example').timeAutocomplete({
  2. formatter: '24hr',
  3. });

预览截图