【Bootstrap】Bootstrap Datepicker使用

  插件:http://url.cn/V4S8w4

  1、添加样式和引用JS文件

<link href="CSS/bootstrap-datetimepicker.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script src="js/bootstrap-datetimepicker.js" type="text/javascript"></script>

  如果使用汉化版,引入汉化版,这个JS也在那个下载的文件夹里,并把language设置为“zh-CN”:

<script src="js/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>

  2、设置

  format日期格式:(这个和一般的不一样,开始我就设错了,后来查了才知道)          

  • yyyy-mm-dd
  • yyyy-mm-dd hh:ii
  • yyyy-mm-ddThh:ii
  • yyyy-mm-dd hh:ii:ss
  • yyyy-mm-ddThh:ii:ssZ

  maskInput: true, // disables the text input mask

pickDate: true, // disables the date picker

  pickTime: true, // disables de time picker

  pick12HourFormat: false, // enables the 12-hour format time picker

    pickSeconds: true, // disables seconds in the time picker

  startDate: -Infinity, // set a minimum date

  endDate: Infinity // set a maximum date

  hourStep: 小时的间隔

  minuteStep:分钟的间隔

  secondStep:

  laguage:‘en‘ //zh-CN 

  autoclose:是否选择完后自动关闭

format
String. 默认值: ‘mm/dd/yyyy‘

日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。
p : meridian in lower case (‘am‘ or ‘pm‘) - according to locale file
P : meridian in upper case (‘AM‘ or ‘PM‘) - according to locale file
s : seconds without leading zeros
ss : seconds, 2 digits with leading zeros
i : minutes without leading zeros
ii : minutes, 2 digits with leading zeros
h : hour without leading zeros - 24-hour format
hh : hour, 2 digits with leading zeros - 24-hour format
H : hour without leading zeros - 12-hour format
HH : hour, 2 digits with leading zeros - 12-hour format
d : day of the month without leading zeros
dd : day of the month, 2 digits with leading zeros
m : numeric representation of month without leading zeros
mm : numeric representation of the month, 2 digits with leading zeros
M : short textual representation of a month, three letters
MM : full textual representation of a month, such as January or March
yy : two digit representation of a year
yyyy : full numeric representation of a year, 4 digits
weekStart
Integer. 默认值:0

一周从哪一天开始。0(星期日)到6(星期六)

startDate
Date. 默认值:开始时间

The earliest date that may be selected; all earlier dates will be disabled.

endDate
Date. 默认值:结束时间

The latest date that may be selected; all later dates will be disabled.

daysOfWeekDisabled
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].

autoclose
Boolean. 默认值:false

当选择一个日期之后是否立即关闭此日期时间选择器。

startView
Number, String. 默认值:2, ‘month‘

日期时间选择器打开之后首先显示的视图。 可接受的值:

0 or ‘hour‘ for the hour view
1 or ‘day‘ for the day view
2 or ‘month‘ for month view (the default)
3 or ‘year‘ for the 12-month overview
4 or ‘decade‘ for the 10-year overview. Useful for date-of-birth datetimepickers.
minView
Number, String. 默认值:0, ‘hour‘

日期时间选择器所能够提供的最精确的时间选择视图。

maxView
Number, String. 默认值:4, ‘decade‘

日期时间选择器最高能展示的选择范围视图。

todayBtn
Boolean, "linked". 默认值: false

如果此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。如果是true的话,"Today" 按钮仅仅将视图转到当天的日期,如果是"linked",当天日期将会被选中。

todayHighlight
Boolean. 默认值: false

如果为true, 高亮当前日期。

keyboardNavigation
Boolean. 默认值: true

是否允许通过方向键改变日期。

language
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.

forceParse
Boolean. 默认值: true

当选择器关闭的时候,是否强制解析输入框中的值。也就是说,当用户在输入框中输入了不正确的日期,选择器将会尽量解析输入的值,并将解析后的正确值按照给定的格式format设置到输入框中。

minuteStep
Number. 默认值: 5

此数值被当做步进值用于构建小时视图。对于每个 minuteStep 都会生成一组预设时间(分钟)用于选择。

pickerReferer : 不建议使用
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.

pickerPosition
String. 默认值: ‘bottom-right‘ (还支持 : ‘bottom-left‘)

此选项当前只在组件实现中提供支持。通过设置选项可以讲选择器放倒输入框下方。

viewSelect
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.

showMeridian
Boolean. 默认值: false

This option will enable meridian views for day and hour views.

initialDate
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 ...

设置

  3、例子

<input id="txtDtbegin" name="dtBegin" value="<%=dt2 %>" type="text"  class="form-control">
$(‘#txtDtbegin‘).datetimepicker({
                format: ‘yyyy-mm-dd hh:ii:ss‘,
                language: ‘zh-CN‘,
                pickDate: true,
                pickTime: true,
                inputMask: true,
                pickerPosition: "bottom-left",
                autoclose: true
            });

  在下载的文件里有部分实例。

【Bootstrap】Bootstrap Datepicker使用

时间: 2024-08-11 20:32:38

【Bootstrap】Bootstrap Datepicker使用的相关文章

关于bootstrap的datepicker在meteor应用中的使用(不包含bootstrap框架)

1.安装bootstrap3-datepicker包 meteor add rajit:bootstrap3-datepicker 2.使用方法 Example In your handlebars template: <input type="text" class="form-control" id="my-datepicker"> In client-side JS code: Template.mytemplate.rende

关于bootstrap插件datepicker

<input  readonly size="16" type="text"  name="time" id="time"> 一.设置开始时间结束时间范围 $('#time').datepicker({ format: 'yyyy-mm-dd', weekStart: 1, startDate:new Date(2013,10,27), //开始时间,在这时间之前都不可选 endDate:new Date(),//

Bootstrap的datepicker控件

为input 控件的text 添加datepicker()方法后,原本的控件change事件无法正常触发.原因是项目中同时使用了用了jquery ui,碰巧它里面也有一个datepicker,名字一模一样. 后来,看了一下Jqurey UI 中的Js 源代码,才知道,要使用 ‘changeDate’事件才可以触发,下面的就是例子: $('#so-delivery-date').datepicker().on('changeDate',function() {                   

BootStrap——BootStrap练习(栅格系统、组件、插件)

1.头部:主要运用了栅格系统(对于不同的设备应该如何布局来适应屏幕,如何隐藏元素等) <div class="container"> <div class="row"> <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12"> <img src="img/top1.jpg" /> </div> <div class=&

Html5 native DatePicker和Bootstrap DatePicker的冲突问题

1. Html5 native DatePicker和Bootstrap DatePicker 支持Html5 native DatePicker的浏览器有:Chrome, Opera 11+, Opera Mobile, and iOS 5+,参考http://caniuse.com/#feat=input-datetime Bootstrap.JQuery UI都提供DatePicker组件,本文以Bootstrap为例,https://bootstrap-datepicker.readth

35 个必须有的Bootstrap工具和生成器

Bootstraptor If you think that bootstrap templates are not enough for you, you should go with bootstraptor. You will have a wide range to select from, which automatically gives you a lot of interesting things to work with. Brag Themes Looking for som

(转)Bootstrap 之 Metronic 模板的学习之路 - (4)源码分析之脚本部分

https://segmentfault.com/a/1190000006709967 上篇我们将 body 标签主体部分进行了简单总览,下面看看最后的脚本部门. 页面结尾部分(Javascripts 脚本文件) 我们来看看代码最后的代码,摘取如下: <!--[if lt IE 9]> <script src="../assets/global/plugins/respond.min.js"></script> <script src=&quo

Play1+angularjs+bootstrap ++ (idea + livereload)

我的web开发最强组合:Play1+angularjs+bootstrap ++ (idea + livereload) 时间 2012-12-26 20:57:26  Freewind.me原文  http://freewind.me/blog/20121226/1167.html 首先说明我开发web的情况: 个人开发 前后端全部自己搞定 网站类型多为传统多页面程序 注重开发效率 Javascritp能力不强 美术细胞很少 由于每个人情况不同,选择技术及方案的重点也不同,所以内容仅供参考.对

Flask---使用Bootstrap新建第一个demo

Flask---使用Bootstrap新建第一个demo 参考自http://www.jianshu.com/p/417bcbad82fb 还有<Flask web开发> 前端用到Bootstrap开源框架,Bootstrap是客户端框架,后台当然就是Flask了. 服务器需要做的只是提供引用了Bootstrap层叠样式表(CSS)和JS文件的html响应,并且在html.css和js代码中实例化需要的组件,这些操作的最理想的执行环境就是模板 关于模板的介绍及其实现原理:https://kb.

Bootstrap

第一章:认识Bootstrap Bootstrap的特点:灵活.优雅.可扩展. Bootstrap的定义:简单灵活的用于搭建Web页面的HTML.CSS.JavaScript工具集. Bootstrap中的JS插件依赖于jQuery,因此jQuery要在Bootstrap之前引用. Bootstrap不支持IE8. 第二章:排版 一.全局样式: Bootstrap不再一味的清零,而是注重重置可能产生的样式,保留和坚持部分浏览器的基础样式. 二.标题: Bootstrap定义标题也使用<h1>到