I am building an app that would allow to select two dates, however the first date should only be the current day and the second one should allow to select all days beyond that. In a nutshell - I am struggling to make #deadlinestart show show only current day as available selection. Cheers
我正在构建一个允许选择两个日期的应用程序,但是第一个日期应该只是当天,第二个日期应该允许选择除此之外的所有日期。简而言之 - 我正在努力使#deadlinestart show show只显示当前日期作为可用选择。干杯
Here's my code
这是我的代码
function days() {
var a = $("#deadlinestart").datepicker('getDate').getTime(),
b = $("#deadlineend").datepicker('getDate').getTime(),
c = 24*60*60*1000,
daysleft = Math.round(Math.abs((a - b)/(c)));
$("#totaldaysleft").val(daysleft)
}
$(document).ready(function () {
$.datepicker.setDefaults({dateFormat: 'dd/mm/yy',});
$('#deadlinestart').datepicker({
onSelect: function(selectedDate) {
var minDate = $(this).datepicker('getDate');
if (minDate) {minDate.setDate(minDate.getDate() + 2);}
$('#deadlineend').datepicker('option', 'minDate', minDate || 1);
$('#ui-datepicker-div').append('<p>Now select your deadline.</p>');
days();
}});
$('#deadlineend').datepicker({minDate: 1, onSelect: function(selectedDate) {
$('#ui-datepicker-div').append('<p>zdrw</p>');
var maxDate = $(this).datepicker('getDate');
if (maxDate) {maxDate.setDate(maxDate.getDate() - 1);}
$('#deadlinestart').datepicker('option', 'maxDate', maxDate);
days();
}});
});
2 个解决方案
#1
2
I know this is an old question but it may help someone else. There is no need of datepicker if only current day required,but in some cases the ui will be looks better with a datepicker.
我知道这是一个老问题,但它可能会帮助别人。如果只需要当前日期,则不需要datepicker,但在某些情况下,使用日期选择器会更好看ui。
In jQuery ui datepicker there is an option called minDate
and maxDate
it will do the trick.
在jQuery ui datepicker中有一个名为minDate和maxDate的选项,它可以解决这个问题。
jQuery("#firstDate").datepicker({ minDate: 0,maxDate:0 });
#2
0
for the first date use the following :
对于第一个日期使用以下内容:
<input type="text" name="firstDate" value="<?php echo date('Y-m-d');?>" readonly>
#1
2
I know this is an old question but it may help someone else. There is no need of datepicker if only current day required,but in some cases the ui will be looks better with a datepicker.
我知道这是一个老问题,但它可能会帮助别人。如果只需要当前日期,则不需要datepicker,但在某些情况下,使用日期选择器会更好看ui。
In jQuery ui datepicker there is an option called minDate
and maxDate
it will do the trick.
在jQuery ui datepicker中有一个名为minDate和maxDate的选项,它可以解决这个问题。
jQuery("#firstDate").datepicker({ minDate: 0,maxDate:0 });
#2
0
for the first date use the following :
对于第一个日期使用以下内容:
<input type="text" name="firstDate" value="<?php echo date('Y-m-d');?>" readonly>