自己写的一款基于jquery的日历组件

注:这款组件的开发初衷是觉得jquery领域的日历组件的质量不是特别好,有大部分情况都不太符合业务团队的开发需求,在UI设计方面也没有亮点,所以这款在没有UI设计的情况下,参考elementUI的日历组件的UI设计进行开发,也非常感谢饿了么ued团队的设计,欢迎大家能够在使用中提出相关issue,感谢大家的支持。

Gemini DatePicker

A full-featured datepicker jquery plugin.

Features

  • Supports more configurable options.
  • Supports more methods
  • Supports more events
  • Supports datetime mode
  • Supports range date and range datetime mode
  • Supports internationalization
  • Cross-browser support

Example image

Type: date

Date Image
Type: month

Month Image
Type: year

Year Image
Type: datetime

Datetime Image
Type: date-range

Date range Image
Type: datetime-range

Datetime range Image

Getting started

Quick start
  • Clone the repository: git clone github.com/gregzhang61….
  • Install with Npm: npm install gemini-datepicker.
  • Install with Bower: bower install gemini-datepicker.
Installation
Include files:

Css file

<link rel="stylesheet" href="/assets/css/iconfont.css">
<link rel="stylesheet" href="/css/jquery.datepicker.min.css">复制代码

Javascript file

<script src="/assets/js/jquery.min.js"></script>
<script src="/js/jquery.datepicker.min.js"></script>
// there is no need to import the next line of code when current language is 'en-US'
<script src="/i18n/datepicker.zh-CN.js"></script>复制代码

Attributes

You may set datepicker options with $().datepicker(options), the options type is Object.

NameTypeDefault valueOptional valueDescription
typeString'date'year/month/date/datetime/datetime-range/date-rangetype of the picker
readonlyBooleanfalsefalse/ truewhether DatePicker is read only
disabledBooleanfalsefalse/ truewhether DatePicker is disabled
formatString'yyyy-MM-dd'year->yyyy, month->MM, day->dd, hour->HH, minute->mm, second->ssformat of the picker
placeholderString'Please pick a day'--init input element's placeholder
alignString'left''left'/'center'/'right'the pick panel's alignment
startDateDatenull--If the start date exists, the date before the start date is disabled
endDateDatenull--If the end date exists, the date after the end date is disabled
langString'en-US''en-US'/'zh-CN'/'vi'language of the datepicker
rangeSeparatorString'-'--if type is 'date-range' or 'datetime-range', use rangeSeparator to separate the date
defaultValueString/Date''--default date, if picker type is date-range or datetime-range, picker's type must be String
zIndexNumber2008--The CSS style z-index for the picker.

Methods

Common usage

$().datepicker(methodName, argument1, argument2, ..., argumentN);复制代码
setDate(date)

Set the current date with a new date, parameter date type is String or Date .

$().datepicker('setDate', '2016-02-09');
$().datepicker('setDate', new Date(2016, 1, 9));复制代码
getDate()

Get the current date.

$().datepicker('getDate');复制代码
clear()

Clear the picker date (when date is cleared, the current date is displayed by default).

$().datepicker('clear');复制代码
show()

Show the picker panel.

$().datepicker('show');复制代码
hide()

hide the picker panel.

$().datepicker('hide');复制代码
disable(value)

disable or enable the picker, if parameter value is true that can disable the picker, otherwise can enable the picker.

// disable the picker
$().datepicker('disable', true);
// enable the picker
$().datepicker('disable', false);复制代码
destroy()

Destroy the picker and remove the instance from target element.

$().datepicker('destroy');复制代码

Events

Common usage

$().on(eventName, function (e, arguments) {
  // todo
});复制代码
pick.datepicker

This event fires when date is changed.

  • event ( Type: Object )
    • newDate ( Type: String )
    • oldDate ( Type: String )
$().on('pick.datepicker', function (event) {
  console.log('newDate: ' + event.newDate);
  console.log('oldDate: ' + event.oldDate);
});复制代码
show.datepicker

This event fires when picker is show.

$().on('show.datepicker', function (e) {
  // todo
});复制代码
hide.datepicker

This event fires when picker is hide.

$().on('hide.datepicker', function (e) {
  // todo
});复制代码

Callbacks

Common usage

$().datepicker({
    CallbackName: function () {
      // todo
    }
});复制代码
onChange

A shortcut of the "pick.datepicker" event, this callback called when picker value is changed.

$().datepicker({
    onChange: function (events) {
      console.log('newDate: ' + event.newDate);
      console.log('oldDate: ' + event.oldDate);
    }
});复制代码
onShow

A shortcut of the "show.datepicker" event, this callback called when picker is show.

$().datepicker({
    onShow: function () {
      // todo
    }
});复制代码
onHide

A shortcut of the "hide.datepicker" event, this callback called when picker is hide.

$().datepicker({
    onHide: function () {
      // todo
    }
});复制代码

Locale

I18n config, default language is en-US

Usage
<script src="/js/jquery.datepicker.min.js"></script>
<script src="/i18n/datepicker.zh-CN.js"></script>
<script>
  $().datepicker({
    lang: 'zh-CN'
  });
</script>复制代码

Run example

Please download the project, and then enter into this directory.(download gulp-sass plugin need to connect vpn)

Browser support

  • Chrome Most versions
  • Firefox Most versions
  • Safari Most versions
  • Opera Most versions
  • Edge Most versions
  • Internet Explorer 8+

Author

Greg Zhang from Baidu (gregzhang616@gmail.com).

Remarks

Thanks for the eleme UED team to provide such a good UI design.

转载于:https://juejin.im/post/59bf5f44f265da066b3942f4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值