bootstrap-daterangepicker插件运用
2018-09-05 07:50:27来源:博客园 阅读 ()
引入:daterangepicker.css、daterangepicker.js、moment.js、moment.min.js
链接:https://files.cnblogs.com/files/kitty-blog/moment.min.js、https://files.cnblogs.com/files/kitty-blog/moment.js、https://files.cnblogs.com/files/kitty-blog/daterangepicker.js、https://files.cnblogs.com/files/kitty-blog/daterangepicker.css
/**初始化 Daterangepicker 插件 */ function initDaterangepicker() { $('.daterangepicker').daterangepicker({ "showDropdowns": true, "showWeekNumbers": false, "showISOWeekNumbers": false, "timePicker": true, "timePicker24Hour": true, "timePickerSeconds": false, "autoApply": false, "locale": { "direction": "ltr", "format": "YYYY-MM-DD HH:mm", "separator": " 至 ", "applyLabel": "确定", "cancelLabel": "取消", "fromLabel": "From", "toLabel": "To", "daysOfWeek": [ "周六", "周一", "周二", "周三", "周四", "周五", "周日" ], "monthNames": [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" ], "firstDay": 1 }, "alwaysShowCalendars": false, "parentEl": "daterangepicker", "startDate": moment(), "endDate": moment(), "minDate": false, "maxDate": "05/28/2050", "applyClass": "btn-green btn-outline", "cancelClass": "btn-default btn-outline", "opens": "center", "drops": "down" }, function (start, end, label) { console.log("New date range selected: " + start.format('YYYY-MM-DD HH:mm') + " to " + end.format('YYYY-MM-DD HH:mm') + " (predefined range: " + label + ")"); $("#startTime").val(start.format('YYYY-MM-DD HH:mm')); $("#endTime").val(end.format('YYYY-MM-DD HH:mm')); }); } /**初始化 datetimepicker 日期 插件*/ function initDatepicker(defaultStartDate, defaultEndDate) { var now = new Date(); //date + time var picker1 = $('.datetimepicker-startdate').datetimepicker({ format: 'YYYY-MM-DD', locale: moment.locale('zh-cn'), defaultDate: defaultStartDate, minDate: false, maxDate: false, ignoreReadonly: true, allowInputToggle: true, icons: { time: 'fa fa-clock-o', date: 'fa fa-calendar', up: 'fa fa-chevron-up', down: 'fa fa-chevron-down', previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-crosshairs', clear: 'fa fa-trash' } }); var picker2 = $('.datetimepicker-enddate').datetimepicker({ format: 'YYYY-MM-DD', locale: moment.locale('zh-cn'), defaultDate: defaultEndDate, minDate: defaultStartDate, maxDate: false, ignoreReadonly: true, allowInputToggle: true, icons: { time: 'fa fa-clock-o', date: 'fa fa-calendar', up: 'fa fa-chevron-up', down: 'fa fa-chevron-down', previous: 'fa fa-chevron-left', next: 'fa fa-chevron-right', today: 'fa fa-crosshairs', clear: 'fa fa-trash' } }); //动态设置最小值 picker1.on('dp.change', function (e) { picker2.data('DateTimePicker').minDate(e.date); }); //动态设置最大值 picker2.on('dp.change', function (e) { picker1.data('DateTimePicker').maxDate(e.date); }); } /**初始化 datetimepicker 时间 插件*/ function initTimepicker(defaultStartTime, defaultEndTime) { var now = new Date(); // only time var picker1 = $('.datetimepicker-starttime').datetimepicker({ format: 'LT', locale: moment.locale('zh-cn'), defaultDate: defaultStartTime == "" ? 5 : defaultStartTime, minDate: false, maxDate: false, ignoreReadonly: true, allowInputToggle: true, }); var picker2 = $('.datetimepicker-endtime').datetimepicker({ format: 'LT', locale: moment.locale('zh-cn'), defaultDate: defaultEndTime == "" ? 21 : defaultEndTime, minDate: defaultStartTime, maxDate: false, ignoreReadonly: true, allowInputToggle: true, }); //动态设置最小值 picker1.on('dp.change', function (e) { picker2.data('DateTimePicker').minDate(e.date); }); //动态设置最大值 picker2.on('dp.change', function (e) { picker1.data('DateTimePicker').maxDate(e.date); }); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- Jquery插件写法笔记整理 2020-03-29
- Jquery图形报表插件 jqplot简介及参数详解 2020-03-25
- jQuery插件开发全解析 2020-03-25
- JS判断浏览器是否安装flash插件的简单方法 2020-03-12
- javaScript 逻辑运算符使用技巧整理 2020-03-05
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash