首页 > 其他分享 >bootstrap之双日历时间段选择控件Date Range Picker

bootstrap之双日历时间段选择控件Date Range Picker

时间:2022-11-28 20:36:44浏览次数:68  
标签:Picker 控件 format bootstrap days YYYY moment subtract


Date Range Picker: ​​http://www.daterangepicker.com/​

参考:​​bootstrap之双日历时间段选择控件—daterangepicker(汉化版)​​

下面实现同一页面中 多个 爽日历时间段选择控件 的初始化:

部分 html 代码如下:

<span style="font-size:18px;"><h5 class="tit-header">新增关注人数统计</h5>
<div class="form-control pull-right daterange">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
<div id="increase-chart" class="ibox" style="width: 100%;height:220px;"></div>


<h5 class="tit-header">取消关注人数统计</h5>
<div class="ibox">
<div class="form-control pull-right daterange">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
</div>
<div id="increase-chart" class="ibox" style="width: 100%;height:220px;"></div>


<h5 class="tit-header">净增关注人数统计</h5>
<div class="ibox">
<div class="form-control pull-right daterange">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
</div>
<div id="increase-chart" class="ibox" style="width: 100%;height:220px;"></div>


<h5 class="tit-header">累积关注人数</h5>
<div class="ibox">
<div class="form-control pull-right daterange">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
</div>
<div id="increase-chart" class="ibox" style="width: 100%;height:220px;"></div></span>

其中关键代码为:

<span style="font-size:18px;"><div class="form-control pull-right daterange">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div></span>

定义控件结构样式。

使用 js 对该控件进行初始化:

$(function() {
initDateRangePicker();
});

// 初始化 日期范围选择器
function initDateRangePicker() {
$('.daterange span').html(moment().subtract(7, 'days').format('YYYY-MM-DD') + ' 至 ' + moment().subtract(1, 'days').format('YYYY-MM-DD'));

$('.daterange').daterangepicker({
startDate: moment().subtract(7, 'days'),
endDate: moment().subtract(1, 'days'),
maxDate: moment().subtract(1, 'days'),
ranges: {
'最近7天': [moment().subtract(7, 'days'), moment().subtract(1, 'days')],
'最近15天': [moment().subtract(15, 'days'), moment().subtract(1, 'days')],
'最近30天': [moment().subtract(30, 'days'), moment().subtract(1, 'days')]
},
locale: {
applyLabel : '确定',
cancelLabel : '取消',
fromLabel : '起始时间',
toLabel : '结束时间',
customRangeLabel : '自定义',
daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
'七月', '八月', '九月', '十月', '十一月', '十二月' ],
firstDay : 1
}
}, function(start, end, label) {//格式化日期显示框

console.log(label);


var iconCalendar = '<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>';
var iconCaret = '<b class="caret"></b>';

this.element.html(iconCalendar + ' <span>' + start.format('YYYY-MM-DD') + ' 至 ' + end.format('YYYY-MM-DD') + '</span> ' + iconCaret);
});
}

       需要注意的是:多个日历时间段选择控件初始化中的回调方法(当选择时间段后被触发的函数),为对修改了日期的控件进行修改,而不是全部控件进行修改,需要使用到 this.element 获取当前被修改的空间的 .daterange jQ对象,并进行相应的日期修改。




标签:Picker,控件,format,bootstrap,days,YYYY,moment,subtract
From: https://blog.51cto.com/u_15894233/5893630

相关文章

  • Bootstrap_栅格系统_入门和Bootstrap_栅格系统_注意事项
    Bootstrap_栅格系统_入门:响应式布局:同一套页面可以兼容不同分辨率的设备实现:依赖于栅格系统:将一行平均分成12个格子,可以指定元素占几个格子步骤:1.定义容器,相当于htm......
  • Bootstrap_概述和Bootstrap_快速入门
    Bootstrap_概述:Bootstrap_概述概念:一个前端开发的框架框架:一个半成品软件,开发人员可以在框架基础上,在进行开发,简化编码好处:定义了很多css样式和js插件,我们开发人员直接......
  • 打造 Bootstrap Tags Input 同 Modal 结合的利器
        BoostrapTagsinput的使用:​​http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/​​    BoostrapTagsInput插件基于Bootstrap......
  • 基于Bootstrap使用jQuery实现输入框组input-group的添加与删除-改进版
          上一次说到了​​基于Bootstrap使用jQuery实现输入框组input-group的添加与删除​​ ,初始状态下只有一个输入框组,可以通过点击输入框组的右侧“+”(或自定......
  • WPF保存控件到图片
    ///<summary>///保存控件到图片///</summary>///<paramname="element">控件对象</param>///<paramname="fileName">文件名</param>///<paramname="dpi">DPI......
  • iOS开发之好用的图片选择第三方TZImagePickerController
    最近的项目中涉及到了类似于发布朋友圈的功能,其中就需要上传照片等媒体内容,所以为了方便和效果好看,使用了TZImagePickerController第三方来管理和调用媒体内容,现在就是简单......
  • Swift基础之PickerView(时间)选择器
    代码讲解:(后面有额外代码讲解)首页设计UIPickerView的样式设计:leftArray=["花朵","颜色","形状"];              letarray1=["茉莉","玫瑰","郁金香"......
  • C#清空控件的值
    ///清除容器里面某些控件的值///</summary>///<paramname="parContainer">容器类控件</param>publicvoidClearCntrValue(Contr......
  • 目前主流的几款文件上传控件,以及优缺点
    ​ WebUploader是由BaiduWebFE(FEX)团队开发的一个简单的以HTML5为主,FLASH为辅的现代文件上传组件。在现代的浏览器里面能充分发挥HTML5的优势,同时又不摒弃主流IE浏览器......
  • SAP UI5 SmartTable 控件的使用介绍试读版
    本文来自笔者SAP开发技术交流知识星球内一位朋友的提问:smartfilterbar有个输入框CostElement绑定了cds实现valuehelp请问其对应的suggestion功能是通过cds的注解实现......