minDate and maxDate options are not working in dat

2019-08-07 02:11发布

I'm using the "datepicker" plugin on my project, it's set to decade view, and I want to disable the future dates, for this I have used the maxDate option but it's not working, my code:

$('#data_1 .input-group.date').datepicker({
    todayBtn: "linked",
    maxDate: "0",
    keyboardNavigation: false,
    forceParse: false,
    calendarWeeks: true,
    autoclose: true
});

tried with 0 and new Date

4条回答
爷的心禁止访问
2楼-- · 2019-08-07 02:46

If u are trying calendar for start date and end date then this will help you :)

`$("#from").datepicker({
    format : 'dd-mm-yyyy',
    endDate: '<?php echo $to; ?>',
    changeMonth: false,
    changeYear: false,
    prevText: '<i class="fa fa-chevron-left"></i>',
    nextText: '<i class="fa fa-chevron-right"></i>',
    onClose: function (selectedDate) {
        $("#to").datepicker("option", "startDate", selectedDate);
    }
});
$("#to").datepicker({
    format : 'dd-mm-yyyy',
    startDate: '<?php echo $from; ?>',
    changeMonth: false,
    changeYear: false,
    prevText: '<i class="fa fa-chevron-left"></i>',
    nextText: '<i class="fa fa-chevron-right"></i>',
    onClose: function (selectedDate) {
        $("#from").datepicker("option", "endDate", selectedDate);
    }
});`
查看更多
疯言疯语
3楼-- · 2019-08-07 02:51

Try below code:

var today = new Date();  
$('#data_1 .input-group.date').datepicker({
            todayBtn: "linked",
            endDate: "today",
            maxDate: today
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });

Also you can try with:

 maxDate: 0
查看更多
We Are One
4楼-- · 2019-08-07 03:04

Note that bootstrap-datepicker has no maxDate option, you have to use endDate.

Here a working sample:

$("#datepicker").datepicker({
  todayBtn: "linked",
  endDate: new Date(),
  keyboardNavigation: false,
  forceParse: false,
  calendarWeeks: true,
  autoclose: true
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>

<input type="text" class="form-control" id="datepicker">

查看更多
家丑人穷心不美
5楼-- · 2019-08-07 03:06

Adding attribute data-date-end-date="0d" worked for me:

<input type="text" id="birthDay" data-date-end-date="0d">
查看更多
登录 后发表回答