Jquery UI Datepicker - Period
Расширение Datepicker для выбора периода
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://jquery-ui-bootstrap.github.io/jquery-ui-bootstrap/css/custom-theme/jquery-ui-1.10.3.custom.css">
<script src="https://rawgit.com/Artemeey/5ebc39370e568c34f03dce1639cabee8/raw/8de40b26479c406ee9cd6f9b4b3f4ad05370a024/jquery.datepicker.extension.range.min.js"></script>
Выберите период:
<br>
<br>
<div id="date_range"></div>
<br>
<input id="startDate" name="startDate">
<input id="endDate" name="endDate">
<input id="Dates" name="Dates">
CSS
.ui-datepicker .selected-start:not(.selected-end) a,
.ui-datepicker .selected-end:not(.selected-start) a {
background: #F3FDD5;
}
.ui-datepicker .selected.first-of-month:not(.selected-start) a {
border-left: 2px dotted #D4E7F6;
padding-left: 1px;
}
.ui-datepicker .selected.last-of-month:not(.selected-end) a {
border-right: 2px dotted #D4E7F6;
padding-right: 1px;
}
div.datepicker {
position: relative;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
width: 196px;
height: 147px;
position: absolute;
top: 0;
left: 0;
display: none;
}
.datepickerContainer {
background: #FFF;
position: absolute;
top: 0;
left: 0;
}
/*
.datepickerBorderT {
position: absolute;
left: 10px;
top: 0;
right: 10px;
height: 10px;
background: url(../images/custom_t.png);
}
.datepickerBorderB {
position: absolute;
left: 10px;
bottom: 0;
right: 10px;
height: 10px;
background: url(../images/custom_b.png);
}
.datepickerBorderL {
position: absolute;
left: 0;
bottom: 10px;
top: 10px;
width: 10px;
background: url(../images/custom_l.png);
}
.datepickerBorderR {
position: absolute;
right: 0;
bottom: 10px;
top: 10px;
width: 10px;
background: url(../images/custom_r.png);
}
.datepickerBorderTL {
position: absolute;
top: 0;
left: 0;
width: 10px;
height: 10px;
background: url(../images/custom_tl.png);
}
.datepickerBorderTR {
position: absolute;
top: 0;
right: 0;
width: 10px;
height: 10px;
background: url(../images/custom_tr.png);
}
.datepickerBorderBL {
position: absolute;
bottom: 0;
left: 0;
width: 10px;
height: 10px;
background: url(../images/custom_bl.png);
}
.datepickerBorderBR {
position: absolute;
bottom: 0;
right: 0;
width: 10px;
height: 10px;
background: url(../images/custom_br.png);
}
*/
.datepickerBorderL {
position: absolute;
}
.datepickerBorderR {
position: absolute;
}
.datepickerBorderBL {
position: absolute;
}
.datepickerBorderBR {
position: absolute;
}
.datepickerHidden {
display:...
JavaScript
var startDate, endDate, Dates = [];
$(function() {
$('#date_range').datepicker({
range: 'period', // режим - выбор периода
numberOfMonths: 3,
onSelect: function(dateText, inst, extensionRange) {
// extensionRange - объект расширения
$('[name=startDate]').val(extensionRange.startDateText);
$('[name=endDate]').val(extensionRange.endDateText);
}
});
$('#date_range').datepicker('setDate', ['+4d', '+8d']);
// объект расширения (хранит состояние календаря)
var extensionRange = $('#date_range').datepicker('widget').data('datepickerExtensionRange');
if(extensionRange.startDateText) $('[name=startDate]').val(extensionRange.startDateText);
if(extensionRange.endDateText) $('[name=endDate]').val(extensionRange.endDateText);
});