但愿这个小小的项目能帮到你 !javascript
Tags: twitter-bootstrap, datetime, picker, component, javascript, widgetcss
须要bootstrap的下拉菜单组件 (dropdowns.less) 的某些样式,还有bootstrap的sprites (sprites.less and associated images) 中的箭头图标。html
A standalone .css file (including necessary dropdown styles and alternative, text-based arrows) can be generated by runningbuild/build_standalone.less through the lessc compiler:java
全部须要"Date" 的选项均可以处理Date 对象; a String formatted according to the given format; or a timedelta relative to today, eg '-1d', '+6m +1y', etc, where valid units are 'd' (day), 'w' (week), 'm' (month), and 'y' (year).git
你也能够指定一个符合 ISO-8601 格式的日期时间,就能够忽略下面的格式:github
String. 默认值: 'mm/dd/yyyy'bootstrap
日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。app
Integer. 默认值:0less
一周从哪一天开始。0(星期日)到6(星期六)ide
Date. 默认值:开始时间
The earliest date that may be selected; all earlier dates will be disabled.
Date. 默认值:结束时间
The latest date that may be selected; all later dates will be disabled.
String, Array. 默认值: '', []
Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: '0,6' or [0,6].
Boolean. 默认值:false
当选择一个日期以后是否当即关闭此日期时间选择器。
Number, String. 默认值:2, 'month'
日期时间选择器打开以后首先显示的视图。 可接受的值:
Number, String. 默认值:0, 'hour'
日期时间选择器所可以提供的最精确的时间选择视图。
Number, String. 默认值:4, 'decade'
日期时间选择器最高能展现的选择范围视图。
Boolean, "linked". 默认值: false
若是此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。若是是true的话,"Today" 按钮仅仅将视图转到当天的日期,若是是"linked",当天日期将会被选中。
Boolean. 默认值: false
若是为true, 高亮当前日期。
Boolean. 默认值: true
是否容许经过方向键改变日期。
String. 默认值: 'en'
The two-letter code of the language to use for month and day names. These will also be used as the input's value (and subsequently sent to the server in the case of form submissions). Currently ships with English ('en'), German ('de'), Brazilian ('br'), and Spanish ('es') translations, but others can be added (see I18N below). If an unknown language code is given, English will be used.
Boolean. 默认值: true
当选择器关闭的时候,是否强制解析输入框中的值。也就是说,当用户在输入框中输入了不正确的日期,选择器将会尽可能解析输入的值,并将解析后的正确值按照给定的格式format设置到输入框中。
Number. 默认值: 5
此数值被当作步进值用于构建小时视图。对于每一个 minuteStep 都会生成一组预设时间(分钟)用于选择。
String. 默认值: 'default' (other value available : 'input')
The referer element to place the picker for the component implementation. If you want to place the picker just under the input field, just specify input.
String. 默认值: 'bottom-right' (还支持 : 'bottom-left')
此选项当前只在组件实现中提供支持。经过设置选项能够讲选择器放倒输入框下方。
Number or String. 默认值: same as minView (supported values are: 'decade', 'year', 'month', 'day', 'hour')
With this option you can select the view from which the date will be selected. By default it's the last one, however you can choose the first one, so at each click the date will be updated.
Boolean. 默认值: false
This option will enable meridian views for day and hour views.
Date or String. 默认值: new Date()
You can initialize the viewer with a date. By default it's now, so you can specify yesterday or today at midnight ...
组件模版。
带有重置按钮(用于清空输入框)的组件模版。
初始化日期时间选择器。
参数: None
移除日期时间选择器。同时移除已经绑定的event、内部绑定的对象和HTML元素。
参数: None
显示日期时间选择器。
参数: None
隐藏日期时间选择器。
参数: None
使用当前输入框中的值更新日期时间选择器。
参数:
给日期时间选择器设置一个新的起始日期。
Omit startDate (or provide an otherwise falsey value) to unset the limit.
参数:
给日期时间选择器设置结束日期。
Omit endDate (or provide an otherwise falsey value) to unset the limit.
参数:
Sets the days of week that should be disabled.
Omit daysOfWeekDisabled (or provide an otherwise falsey value) to unset the disabled days.
Datetimepicker 类暴露了一组event用以对日期进行操做。
当选择器显示时被触发。
当选择器隐藏时被触发。
当日期被改变时被触发。
当十年视图上的年视图view被改变时触发。
当年视图上的月视图view被改变时触发。
当用户选择的日期超出startDate 或endDate 时,或者经过setDate 或 setUTCDate方法设置日期超出范围时被触发。
日期时间选择器提供了键盘导航:
这些方向键中,left/right 向后/向前 一天,up/down 向后/向前 一周。
配合shift键,up/left 向后退一个月,down/right 向前进一个月。
配置ctrl键,up/left 向后退一年,down/right 向前进一年。
Shift+ctrl 和 ctrl 同等效果 - 也就是说,他们不能同时改变月和年,只能单独改变年。
escape 键能够用来隐藏、从新显示日期时间选择器;当用户但愿手工编辑输入框中的值是会颇有用。
当选择器处于显示状态时,enter键只是将其隐藏。当选择器处于隐藏状态时,enter键发挥一般的功能 - 提交当前表单,或者其余。
本插件支持月、每周中天的名称、weekStart选项的国际化。默认是语言是English ('en');其它可使用的翻译文件在js/locales/ 目录中,只需在本插件以后引入须要的语言文件便可。须要增长额外语言支持的话,只需向 $.fn.datetimepicker.dates中增长一个key便可,必定要放在调用 .datetimepicker()以前。以下案例:
Right-to-left languages may also include rtl: true to make the calendar display appropriately.
If your browser (or those of your users) is displaying characters wrong, chances are the browser is loading the javascript file with a non-unicode encoding. Simply add charset="UTF-8" to your script tag:
绑定输入框,并设置format选项:
绑定输入框,并设置format标记:
做为组件使用:
做为内联日期时间选择器:
实际应用中可能会根据日期字段查询某个日期范围内的数据,则须要对日期选择器可选时间进行限制,
如:开始时间不能大于结束时间,结束时间不能小于开始时间,此时就要为开始日期选择器和结束日期选择器动态的设置startDate和endDate的值。
2、相关知识点
一、bootstrap-datepicker的初始化
引入bootstrap-datepicker.js和bootstrap-datepicker.css
bootstrap-datepicker配置参数的了解
二、boostrap-datepicker的changeDate事件:日期改变时触发
三、bootstrap-datepicker的setEndDate和setStartDate方法
四、详细配置参见官方文档http://bootstrap-datepicker.readthedocs.org/en/latest/methods.html
3、应用实例
一、JSP中,声明日期选择器
二、JS中,对日期选择器进行初始化和配置