html:
<div id="reportrange" style="display:inline-block;background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 230px;height:33px;">
<i class="fa fa-calendar"></i>
<span></span> <i class="fa fa-caret-down"></i>
</div>
js:
var start = moment().subtract(6, 'days');
var end = moment();
function cb(start, end) {
$('#reportrange span').html(start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
if(start.format("YYYY-MM-DD")==end.format("YYYY-MM-DD")){
$("#timetype").selectpicker('val','hour')
}
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'近7天': [moment().subtract(6, 'days'), moment()],
'近15天': [moment().subtract(14, 'days'), moment()],
'近30天': [moment().subtract(29, 'days'), moment()],
}
}, cb);
cb(start, end);