如何使日期选择器仅在当天后的某一天进行选择

时间:2017-04-19 07:51:24

标签: jquery datepicker

我使用以下jQuery代码将日期输入到输入字段中,以便获得class Environment(models.Model): fullname = models.CharField(max_length=45) ... sla = models.ManyToManyField(SLA, through='EnvironmentSLA') creation_date = models.DateTimeField(auto_now_add=True) class Meta: unique_together = (('fullname', 'projectid', 'regionid', 'account'),) class SLA(models.Model): description = models.CharField(max_length=255) reaction_time = models.CharField(max_length=45) service_level = models.CharField(max_length=45) creation_date = models.DateTimeField(auto_now_add=True) class EnvironmentSLA(models.Model): PLANNED = 'pl' EFFECTIVE = 'ef' DEPRECATED = 'dp' SLA_STATE = ( ( PLANNED, 'planned' ), ( EFFECTIVE, 'effective'), ( DEPRECATED, 'deprecated'), ) environment = models.ForeignKey('Environment', on_delete=models.CASCADE) sla = models.ForeignKey(SLA, on_delete=models.CASCADE) state = models.CharField(max_length=2, choices=SLA_STATE, default=PLANNED) "from"日期输入。

"to"

如果我选择第一个日期为19-04-2017,则第二个日期自动从19-04-2017开始。 问题是:如何让我的第二个日期仅在第一个选定日期后一天开始计算?

意思是它将是20-04-2017而不是19 ......

Here you can see my entire fiddle

希望你能提供帮助。

3 个答案:

答案 0 :(得分:2)

试试这个:

php bin/console assets:install
php bin/console assetic:dump

Working Fiddle

答案 1 :(得分:1)

您只需要这个(如下所示更改onSelect): -

onSelect: function (date) {
    var dt2 = $('#dt2');
    var startDate = $(this).datepicker('getDate','+1d');
    startDate.setDate(startDate.getDate()+1); 
    dt2.datepicker('option', 'minDate', startDate);
    dt2.datepicker('setDate', startDate);
}

答案 2 :(得分:0)

试试这个。它会工作如你所说

 $(function(){

    $('#FromDate').datepicker({
        minDate: "1",
        dateFormat: 'dd-mm-yy',
            onSelect: function () {
            var dt2 = $('#ToDate');
            var startDate = $(this).datepicker('getDate');
            startDate.setDate(startDate.getDate() + 1);
            var minDate = $(this).datepicker('getDate');
            dt2.datepicker('setDate', startDate);
            dt2.datepicker('option', 'minDate', startDate);
        }
    });


});

$(function(){

        $('#ToDate').datepicker({
                minDate: "0",
                dateFormat: 'dd-mm-yy'
        });

});