jquery datepicker设置思想 [英] jquery datepicker set mindate
问题描述
我有两个jQuery日期选择器来选择从和到日期。我有以下代码,如果您在第一个中选择6月15日然后在第二个中,您现在只能从第15个开始选择。
I have two jQuery datepickers to select a from and to dates. I have the following code that if you select the 15th June in the first then in the second you now can only select from the 15th onwards.
我遇到的问题是我确实需要将设置为 datepicker为+1天。所以用户只能选择第16名。
The issue I have is I really need to set the to datepicker to +1 day. So the user could only select 16th onwards.
我的技能不够高,无法将日期添加到parseDate
My skills are not advanced enough to add the date to the parseDate
$(function() {
var dates = $( "#from_date, #to_date" ).datepicker({
dateFormat: 'dd-mm-yy',
minDate: 0,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
推荐答案
要根据另一个限制一个日期选择器,可以将 minDate
和 maxDate
设置设置为在另一个日期选择器等中选择的日期。
To limit one datepicker based on the other, one can set the minDate
and maxDate
settings to the date selected in the other datepicker etc.
这样的东西
$(function() {
/* global setting */
var datepickersOpt = {
dateFormat: 'dd-mm-yy',
minDate : 0
}
$("#from_date").datepicker($.extend({
onSelect: function() {
var minDate = $(this).datepicker('getDate');
minDate.setDate(minDate.getDate()+2); //add two days
$("#to_date").datepicker( "option", "minDate", minDate);
}
},datepickersOpt));
$("#to_date").datepicker($.extend({
onSelect: function() {
var maxDate = $(this).datepicker('getDate');
maxDate.setDate(maxDate.getDate()-2);
$("#from_date").datepicker( "option", "maxDate", maxDate);
}
},datepickersOpt));
});
这篇关于jquery datepicker设置思想的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!