一个新奇且移动友好的jQuery时间选择器插件,可以让您为输入字段创建一个交互式的、受Android启发的模拟时钟风格的时间选择器。
1.创建一个普通文本字段,并在价值
属性
- <input class="time" type="text" value="14:30" />
2.下载插件,然后插入JavaScript文件jquery-锁定时间picker.min.js
在jQuery之后但在结束body标记之前。
- <script src="//code.jquery.com/jquery.min.js"></script>
- <script src="jquery-clock-timepicker.min.js"></script>
3.调用函数时钟时间选择器
在输入字段上完成。
- $('.time').clockTimePicker();
4.可以使用options参数覆盖的所有默认设置。
- $('.time').clockTimePicker({
- // displays the afternoon hours in the outer circle instead of the inner circle
- afternoonHoursInOuterCircle: false,
- // If you set this option to true, popup is always opened to select hours first before selecting the minutes.
- alwaysSelectHoursFirst: false,
- // auto resize
- autosize: false,
- // custom colors
- colors: {
- buttonTextColor: '#0797FF',
- clockFaceColor: '#EEEEEE',
- clockInnerCircleTextColor: '#888888',
- clockInnerCircleUnselectableTextColor: '#CCCCCC',
- clockOuterCircleTextColor: '#000000',
- clockOuterCircleUnselectableTextColor: '#CCCCCC',
- hoverCircleColor: '#DDDDDD',
- popupBackgroundColor: '#FFFFFF',
- popupHeaderBackgroundColor: '#0797FF',
- popupHeaderTextColor: '#FFFFFF',
- selectorColor: '#0797FF',
- selectorNumberColor: '#FFFFFF',
- signButtonColor: '#FFFFFF',
- signButtonBackgroundColor: '#0797FF'
- },
- // Determine whether to show browser's context menu on right click
- contextmenu: false,
- // If true, the hours can be greater than 23.
- duration: false,
- // If true, the duration can be negative.
- // This settings only has effect if the setting duration is set to true.
- durationNegative: false,
- // font options
- fonts: {
- fontFamily: 'Arial',
- clockOuterCircleFontSize: 14,
- clockInnerCircleFontSize: 12,
- buttonFontSize: 20
- },
- // hides the unselectable number
- hideUnselectableNumbers: false,
- // i18n
- i18n: {
- okButton: 'OK',
- cancelButton: 'Cancel'
- },
- // min/max times
- maximum: '23:59',
- minimum: '-23:59',
- // animation speed when switching modes
- modeSwitchSpeed: 500,
- // only shows clock on mobile device
- onlyShowClockOnMobile: false,
- // callbacks
- onAdjust: function(newVal, oldVal) { /*console.log('Value adjusted from ' + oldVal + ' to ' + newVal + '.');*/ },
- onChange: function(newVal, oldVal) { /*console.log('Value changed from ' + oldVal + ' to ' + newVal + '.');*/ },
- onClose: function() { },
- onModeSwitch: function() { },
- onOpen: function() { },
- // width of the popup in the Desktop
- popupWidthOnDesktop: 200,
- // precision
- precision: 1,
- // if this option is set to true, a user cannot empty the field by hitting delete or backspace.
- required: false,
- // custom separator
- separator: ':',
- // if true, positive durations use the plus sign (+) as a prefix.
- useDurationPlusSign: false,
- // if true, the mobile phone vibrates while changing the time.
- vibrate: true
- });
5.您也可以通过数据选项
属性如下:
- <input class="time" type="text" data-precision="2" data-minimum="09:00" data-maximum="21:00">
6.以编程方式设置时间值:
- $('.time').clockTimePicker('value', '10:05');
7.以编程方式关闭和打开时间选择器:
- $('.time').clockTimePicker('show');
- $('.time').clockTimePicker('hide');
8.销毁时间选择器:
- $('.time').clockTimePicker('dispose');
9.设置并获取值:
- // Get value
- $('.time').clockTimePicker('value');
- // OR
- $('.time').clockTimePicker('val');
- // Set value
- $('.time').clockTimePicker('value', '08:00');
- // OR
- $('.time').clockTimePicker('val', '08:00');
v2.6.3版本(2022-10-27)
v2.6.2版本(2022-03-02)
v2.6.1版本(2022-02-25)
v2.6.0版本(2022-02-23)
v2.5.0 (2021-10-31)
v2.4.0 (2021-02-12)
v2.3.5版本(2020-03-11)
v2.3.4版本(2020-02-19)
v2.3.3版本(2020-02-18)
v2.3.2版本(2019-09-02)
v2.3.1版本(2018-09-04)
v2.3.0版本(2018-08-09)
v2.2.5版本(2018-03-21)
2018-02-08
2018-02-07
2018-02-06
2017-12-09
2017-11-22
2017-09-13
2017-09-11
2017-08-19
2017-06-10
2017-06-09
2017-05-22