DateTimePicker:设置日期范围和之后的第三个日期
DateTimePicker: setting a range of dates and a third date afterwards
我需要使用插件设置日期范围 DateTimePicker 加上此范围之后的特定第三个日期。
这是我目前的代码:
HTML
<div class="form-group">
<label for="startdate" class="control-label">Start Date</label>
<div class="input-group date" id="startdate">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon text-primary"></span>
</span>
</div><!-- input-group -->
</div><!-- form-group -->
<div class="form-group">
<label for="enddate" class="control-label">End Date</label>
<div class="input-group date" id="enddate">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon text-primary"></span>
</span>
</div><!-- input-group -->
</div><!-- form-group -->
<div class="form-group">
<label for="thirddate" class="control-label">Third Date</label>
<div class="input-group date" id="thirddate">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon text-primary"></span>
</span>
</div><!-- input-group -->
</div><!-- form-group -->
JAVASCRIPT
$(function () {
//Enablabling linked pickers
$('#startdate,#enddate,#thirddate').datetimepicker({
format: 'MM/DD/YYYY',
useCurrent: false
});
//Setting the range of dates
$("#startdate").on("dp.change", function (e) {
$('#enddate').data("DateTimePicker").minDate(e.date);
});
$("#enddate").on("dp.change", function (e) {
$('#startdate').data("DateTimePicker").maxDate(e.date);
});
//Setting a third date in the future after the range
$("#thirddate").on("dp.change", function (e) {
$('#enddate').data("DateTimePicker").minDate(e.date);
});
});
该范围的 DateTimePickers 工作正常,但第三个不是,因为它没有正确获取 minDate 值。
希望这对您有所帮助。第三个日期选择器允许选择结束日期之后的日期。
<script>
$(document).ready(function () {
//Enablabling linked pickers
$('#startdate,#enddate,#thirddate').datetimepicker({
format: 'MM/DD/YYYY',
useCurrent: false
});
//Setting the range of dates
$("#startdate").on("dp.change", function (e) {
$('#enddate').data("DateTimePicker").minDate(e.date);
});
$("#enddate").on("dp.change", function (e) {
$('#startdate').data("DateTimePicker").maxDate(e.date);
$('#thirddate').data("DateTimePicker").minDate(e.date); //Added this
});
/* Remove this */
//Setting a third date in the future after the range
//$("#thirddate").on("dp.change", function (e) {
// $('#enddate').data("DateTimePicker").minDate(e.date);
//});
})
</script>
我需要使用插件设置日期范围 DateTimePicker 加上此范围之后的特定第三个日期。
这是我目前的代码:
HTML
<div class="form-group">
<label for="startdate" class="control-label">Start Date</label>
<div class="input-group date" id="startdate">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon text-primary"></span>
</span>
</div><!-- input-group -->
</div><!-- form-group -->
<div class="form-group">
<label for="enddate" class="control-label">End Date</label>
<div class="input-group date" id="enddate">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon text-primary"></span>
</span>
</div><!-- input-group -->
</div><!-- form-group -->
<div class="form-group">
<label for="thirddate" class="control-label">Third Date</label>
<div class="input-group date" id="thirddate">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon-calendar glyphicon text-primary"></span>
</span>
</div><!-- input-group -->
</div><!-- form-group -->
JAVASCRIPT
$(function () {
//Enablabling linked pickers
$('#startdate,#enddate,#thirddate').datetimepicker({
format: 'MM/DD/YYYY',
useCurrent: false
});
//Setting the range of dates
$("#startdate").on("dp.change", function (e) {
$('#enddate').data("DateTimePicker").minDate(e.date);
});
$("#enddate").on("dp.change", function (e) {
$('#startdate').data("DateTimePicker").maxDate(e.date);
});
//Setting a third date in the future after the range
$("#thirddate").on("dp.change", function (e) {
$('#enddate').data("DateTimePicker").minDate(e.date);
});
});
该范围的 DateTimePickers 工作正常,但第三个不是,因为它没有正确获取 minDate 值。
希望这对您有所帮助。第三个日期选择器允许选择结束日期之后的日期。
<script>
$(document).ready(function () {
//Enablabling linked pickers
$('#startdate,#enddate,#thirddate').datetimepicker({
format: 'MM/DD/YYYY',
useCurrent: false
});
//Setting the range of dates
$("#startdate").on("dp.change", function (e) {
$('#enddate').data("DateTimePicker").minDate(e.date);
});
$("#enddate").on("dp.change", function (e) {
$('#startdate').data("DateTimePicker").maxDate(e.date);
$('#thirddate').data("DateTimePicker").minDate(e.date); //Added this
});
/* Remove this */
//Setting a third date in the future after the range
//$("#thirddate").on("dp.change", function (e) {
// $('#enddate').data("DateTimePicker").minDate(e.date);
//});
})
</script>