jQuery datepicker to prevent past date

后端 未结 15 2830
生来不讨喜
生来不讨喜 2020-12-04 16:34

How do I disable past dates on jQuery datepicker? I looked for options but don\'t seem to find anything that indicates the ability to disable past dates.

UPDATE: Th

相关标签:
15条回答
  • 2020-12-04 17:16

    You just need to specify a minimum date - setting it to 0 means that the minimum date is 0 days from today i.e. today. You could pass the string '0d' instead (the default unit is days).

    $(function () {
        $('#date').datepicker({ minDate: 0 });
    });
    
    0 讨论(0)
  • 2020-12-04 17:17

    This should work <input type="text" id="datepicker">

    var dateToday = new Date();
    $("#datepicker").datepicker({
        minDate: dateToday,
        onSelect: function(selectedDate) {
        var option = this.id == "datepicker" ? "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);
        }
    });
    
    0 讨论(0)
  • 2020-12-04 17:19

    //disable future dates

    $('#datetimepicker1').datetimepicker({
                format: 'DD-MM-YYYY',
                maxDate: new Date
            }); 
    

    //disable past dates

     $('#datetimepicker2').datetimepicker({
            format: 'DD-MM-YYYY',
            minDate: new Date
        });
    
    0 讨论(0)
提交回复
热议问题