disable past dates on datepicker

前端 未结 22 1189
梦毁少年i
梦毁少年i 2020-11-29 06:03

How to disable past dates from the current date on a datetimepicker? I tried few posts for similar question but was unable to achieve it, Below is what I tried



        
相关标签:
22条回答
  • 2020-11-29 06:16

    try this,

    $( "#datepicker" ).datepicker({ minDate: new Date()});
    

    Here, new Date() implies today's date....

    0 讨论(0)
  • 2020-11-29 06:16
    <div class="input-group date" data-provide="datepicker" data-date-start-date="0d">
        <input type="text" class="form-control" id="input_id" name="input_name" />
        <div class="input-group-addon">
            <span class="glyphicon glyphicon-calendar"></span>
        </div>
    </div> 
    
    0 讨论(0)
  • 2020-11-29 06:18

    Problem fixed :)

    below is the working code

    $(function(){
        $('#datepicker').datepicker({
            startDate: '-0m'
            //endDate: '+2d'
        }).on('changeDate', function(ev){
            $('#sDate1').text($('#datepicker').data('date'));
            $('#datepicker').datepicker('hide');
        });
    
    })
    
    0 讨论(0)
  • 2020-11-29 06:20

    minDate: dateToday Or minDate: '0' is the key here. Try to set the minDate property.

    $(function() {
        $( "#datepicker" ).datepicker({
            numberOfMonths: 2,
            showButtonPanel: true,
            minDate: dateToday // minDate: '0' would work too
        });
    });
    

    Read more

    0 讨论(0)
  • 2020-11-29 06:21

    Give zero to mindate and it'll disabale past dates.

    $( "#datepicker" ).datepicker({ minDate: 0});
    

    here is a Live fiddle working example http://jsfiddle.net/mayooresan/ZL2Bc/

    The official documentation is available here

    0 讨论(0)
  • 2020-11-29 06:21

    Try this,

    $("#datetimepicker2").datepicker({ startDate: "+0d" });
    
    0 讨论(0)
提交回复
热议问题