Bootstrap3 datetimepicker控件的使用

Bootstrap3 日期+时间选择控件

1.支持日期选择,格式设定

2.支持时间选择

3.支持时间段选择控制

4.支持中文

官网地址:http://eonasdan.github.io/bootstrap-datetimepicker/

git地址:https://github.com/Eonasdan/bootstrap-datetimepicker

moment语言包:https://github.com/moment/moment

datetimepicker使用配置说明:http://eonasdan.github.io/bootstrap-datetimepicker/Options/

moment时间格式化使用说明:http://momentjs.com/docs/

使用方法,引用的文件:

[html]  view plain  copy
  1. <script src="../Js/jquery-1.11.3.min.js">script>  
  2. <link href="../Js/bootstrap-3.3.5-dist/css/bootstrap.css" rel="stylesheet" />  
  3. <script src="../Js/bootstrap-3.3.5-dist/js/bootstrap.min.js">script>  
  4.   
  5. <link href="../Js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />  
  6. <script src="../Js/bootstrap-datetimepicker/js/moment-with-locales.min.js">script>  
  7. <script src="../Js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js">script>  

实例1:,简单配置:

[html]  view plain  copy
  1. <div class="row">  
  2.     <div class='col-sm-6'>  
  3.         <div class="form-group">  
  4.             <label>选择日期:label>  
  5.               
  6.             <div class='input-group date' id='datetimepicker1'>  
  7.                 <input type='text' class="form-control" />  
  8.                 <span class="input-group-addon">  
  9.                     <span class="glyphicon glyphicon-calendar">span>  
  10.                 span>  
  11.             div>  
  12.         div>  
  13.     div>  
  14.     <div class='col-sm-6'>  
  15.         <div class="form-group">  
  16.             <label>选择日期+时间:label>  
  17.               
  18.             <div class='input-group date' id='datetimepicker2'>  
  19.                 <input type='text' class="form-control" />  
  20.                 <span class="input-group-addon">  
  21.                     <span class="glyphicon glyphicon-calendar">span>  
  22.                 span>  
  23.             div>  
  24.         div>  
  25.     div>  
  26. div>  
[javascript]  view plain  copy
  1. $(function () {  
  2.     $('#datetimepicker1').datetimepicker({  
  3.         format: 'YYYY-MM-DD',  
  4.         locale: moment.locale('zh-cn')  
  5.     });  
  6.     $('#datetimepicker2').datetimepicker({  
  7.         format: 'YYYY-MM-DD hh:mm',  
  8.         locale: moment.locale('zh-cn')  
  9.     });  
  10. });  

实例2,选择时间段:

[html]  view plain  copy
  1. <div class="row">  
  2.     <div class='col-sm-6'>  
  3.         <div class="form-group">  
  4.             <label>选择开始时间:label>  
  5.               
  6.             <div class='input-group date' id='datetimepicker1'>  
  7.                 <input type='text' class="form-control" />  
  8.                 <span class="input-group-addon">  
  9.                     <span class="glyphicon glyphicon-calendar">span>  
  10.                 span>  
  11.             div>  
  12.         div>  
  13.     div>  
  14.     <div class='col-sm-6'>  
  15.         <div class="form-group">  
  16.             <label>选择结束时间:label>  
  17.               
  18.             <div class='input-group date' id='datetimepicker2'>  
  19.                 <input type='text' class="form-control" />  
  20.                 <span class="input-group-addon">  
  21.                     <span class="glyphicon glyphicon-calendar">span>  
  22.                 span>  
  23.             div>  
  24.         div>  
  25.     div>  
  26. div>  
[javascript]  view plain  copy
  1. $(function () {  
  2.     var picker1 = $('#datetimepicker1').datetimepicker({  
  3.         format: 'YYYY-MM-DD',  
  4.         locale: moment.locale('zh-cn'),  
  5.         //minDate: '2016-7-1'  
  6.     });  
  7.     var picker2 = $('#datetimepicker2').datetimepicker({  
  8.         format: 'YYYY-MM-DD',  
  9.         locale: moment.locale('zh-cn')  
  10.     });  
  11.     //动态设置最小值  
  12.     picker1.on('dp.change'function (e) {  
  13.         picker2.data('DateTimePicker').minDate(e.date);  
  14.     });  
  15.     //动态设置最大值  
  16.     picker2.on('dp.change'function (e) {  
  17.         picker1.data('DateTimePicker').maxDate(e.date);  
  18.     });  
  19. });  

实例3,使用CDN的文件链接示例:

js引用:

[html]  view plain  copy
  1. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js">script>  
  2. <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">  
  3. <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js">script>  
  4.   
  5. <script src="https://cdn.bootcss.com/moment.js/2.18.1/moment-with-locales.min.js">script>  
  6. <link href="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" rel="stylesheet">  
  7. <script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js">script>  


Html代码:

[html]  view plain  copy
  1. <div class="row">  
  2.     <div class="col-sm-6">  
  3.         <div class="form-group">  
  4.             <label for="">选择日期:label>  
  5.             <div class="input-group date" id='date1'>  
  6.                 <input type="text" class="form-control">  
  7.                 <span class="input-group-addon">  
  8.                     <i class="glyphicon glyphicon-calendar">i>  
  9.                 span>  
  10.             div>  
  11.         div>  
  12.     div>  
  13. div>  

js代码:

[html]  view plain  copy
  1. $(function () {  
  2.     $('#date1').datetimepicker({  
  3.         format: 'YYYY-MM-DD',  
  4.         locale: moment.locale('zh-cn')  
  5.     });  
  6. });  


实例4,在初始化的时候,使用defaultDate指定默认时间:

[javascript]  view plain  copy
  1. $('#datetimepicker1').datetimepicker({  
  2.     format: 'YYYY-MM-DD',  
  3.     locale: moment.locale('zh-cn'),  
  4.     defaultDate: "1990-1-1"  
  5. });  




更多:

jquery.fly.js实现添加购物车效果、实现抛物线运动 

JQuery.validationEngine表单验证插件

RequireJS实例

你可能感兴趣的:(插件)