官网地址:
git地址:https://github.com/Eonasdan/bootstrap-datetimepicker
moment语言包:https://github.com/moment/moment
datetimepicker使用配置说明:
moment时间格式化使用说明:
使用方法,引用的文件:
<script src="https://www.jb51.net/Js/jquery-1.11.3.min.js"></script> <link href="https://www.jb51.net/Js/bootstrap-3.3.5-dist/css/bootstrap.css" /> <script src="https://www.jb51.net/Js/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script> <link href="https://www.jb51.net/Js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" /> <script src="https://www.jb51.net/Js/bootstrap-datetimepicker/js/moment-with-locales.min.js"></script> <script src="https://www.jb51.net/Js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
实例1,简单配置:
<div> <div> <div> <label>选择日期:</label> <!--指定 date标记--> <div> <input type='text' /> <span> <span></span> </span> </div> </div> </div> <div> <div> <label>选择日期+时间:</label> <!--指定 date标记--> <div> <input type='text' /> <span> <span></span> </span> </div> </div> </div> </div>
$(function () {
$('#datetimepicker1').datetimepicker({
format: 'YYYY-MM-DD',
locale: moment.locale('zh-cn')
});
$('#datetimepicker2').datetimepicker({
format: 'YYYY-MM-DD hh:mm',
locale: moment.locale('zh-cn')
});
});
实例2,选择时间段:
<div> <div> <div> <label>选择开始时间:</label> <!--指定 date标记--> <div> <input type='text' /> <span> <span></span> </span> </div> </div> </div> <div> <div> <label>选择结束时间:</label> <!--指定 date标记--> <div> <input type='text' /> <span> <span></span> </span> </div> </div> </div> </div>
$(function () { var picker1 = $('#datetimepicker1').datetimepicker({ format: 'YYYY-MM-DD', locale: moment.locale('zh-cn'), //minDate: '2016-7-1' }); var picker2 = $('#datetimepicker2').datetimepicker({ format: 'YYYY-MM-DD', locale: moment.locale('zh-cn') }); //动态设置最小值 picker1.on('dp.change', function (e) { picker2.data('DateTimePicker').minDate(e.date); }); //动态设置最大值 picker2.on('dp.change', function (e) { picker1.data('DateTimePicker').maxDate(e.date); }); });
如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题: