jQuery 简单可自定义日期和时间选择器插件 jSunPicker

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

简介

jSunPicker是一个全新的jQuery插件,用于在网页上创建高度可配置的日期和时间选择器。

主要特点:

  • 允许将日期和时间选择器绑定到任何DOM元素:内联元素的输入。
  • 允许自定义一周中的第一天。
  • 自定义显示/输出格式。
  • 天和月的自定义标题。
  • 自定义图标。
  • 允许自定义最大/最小日期/时间。
  • 也支持禁用日期。
  • 9个主题。
  • 回调函数。

基本用法:

1.加载样式表jSunPicker.VERSION.css在头部分和JavaScript文件中jSunPicker.VERSION.js按照如下方式加载jQuery库之后:

  1. <!-- Core -->
  2. <link href="src/jSunPicker.VERSION.css" rel="stylesheet" />
  3. <script src="//code.jquery.com/jquery.min.js"></script>
  4. <script src="src/jSunPicker.VERSION.js"></script>
  5. <!-- Optional Themes -->
  6. <link href="themes/jSunPicker.beige.css" rel="stylesheet" />
  7. <link href="themes/jSunPicker.blue.css" rel="stylesheet" />
  8. <link href="themes/jSunPicker.copper.css" rel="stylesheet" />
  9. <link href="themes/jSunPicker.dark.css" rel="stylesheet" />
  10. <link href="themes/jSunPicker.gold.css" rel="stylesheet" />
  11. <link href="themes/jSunPicker.green.css" rel="stylesheet" />
  12. <link href="themes/jSunPicker.grey.css" rel="stylesheet" />
  13. <link href="themes/jSunPicker.pink.css" rel="stylesheet" />
  14. <link href="themes/jSunPicker.purple.css" rel="stylesheet" />
  15. <link href="themes/jSunPicker.white.css" rel="stylesheet" />

2.将日期和时间选择器绑定到输入字段。

  1. $('#datepicker').jSunPicker();

3.通过html自定义日期和时间选择器数据选项属性直接显示在输入字段上。

  1. <input id="datepicker"
  2. data-start-day='1'
  3. data-OPTION='VALUE'
  4. >

4.您也可以像这样在JavaScript中传递配置选项:

  1. $('#datepicker').jSunPicker({
  2. startDay: 1
  3. });

5.所有可用的配置选项和回调功能。

  1. $('#datepicker').jSunPicker({
  2.  
  3. language: 'en-US',
  4. daysTitle: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  5. monthsTitle: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  6.  
  7. // number of characters
  8. dayShort: 2,
  9.  
  10. // number of characters
  11. monthShort: 3,
  12.  
  13. // path/to/calendar/icon, trigger picker on clicking the icon
  14. showIcon: null,
  15.  
  16. // '#element-id', | jQuery selector for the inline container - be sure to give a unique one
  17. inline: null,
  18.  
  19. // Sunday = 1, Saturday = 7
  20. startDay: 1,
  21.  
  22. // Available types: datetime (date+month+year+time), date, month, year, time - set the appropriate formats below
  23. pickerType: 'datetime',
  24.  
  25. // translates to: Sunday, February 1, 1903 23:09:59 | default format: Y/m/d h:m:s //
  26. displayFormat: 'W, T d, Y H:N:S A',
  27.  
  28. // translates to: 9-2-1975 | default format: U
  29. // The following denotes the date and time notations for this script. Mix with the separators for your desired format
  30. // y - two digit year, Y - four digit year, m - month number without leading zero, M - month number with leading zero
  31. // t - month short text, T - month long text, d - date number without leading zero, D - date number with leading zero
  32. // h - hours without leading zero, H - hours with leading zero, a - meridian (am/pm), A - meridian (AM?PM)
  33. // n - minutes without leading zero, N - minutes with leading zero, s - seconds without leading zero,U - unix time
  34. // S - seconds with leading zero, w - day of the week short (dayShort), W - day of the week long, X - military time
  35. outputFormat: 'U',
  36.  
  37. // '2016/03/03', | '[date-string]' in any text format except date first (not like d-m-y or d/mmm/yyyy)
  38. minDate: null,
  39.  
  40. // '2016/03/23', | same as minDate
  41. maxDate: null,
  42.  
  43. // '4:23:45 AM', | '[time-string]' in text format (like 4:23:45 PM)
  44. minTime: null,
  45.  
  46. // '4:23:45 PM', | same as minTime
  47. maxTime: null,
  48.  
  49. // '1,7' | Sun = 1, Sat = 7
  50. disabledDays: null,
  51.  
  52. // individual dates or date ranges separated by commas '2016/03/05,2016/03/10-2016/03/15'
  53. disabledDates: null,
  54.  
  55. // '2016/3/14 12:21:23 PM',
  56. initialDate: null,
  57.  
  58. // triggered when jsunpicker pops up
  59. onShow: $.noop,
  60.  
  61. // triggered after jsunpicker is closed (destroyed)
  62. onClose: $.noop,
  63.  
  64. // triggered when a date is selected
  65. onSelect: $.noop
  66.  
  67. });

更新日志:

2022-06-01

  • 添加了深色主题

2020-10-04

  • 错误修复

2016-04-03

  • 添加了更多CSS主题

预览截图