how to restrict bootstrap date picker from future date

后端 未结 10 1635
无人共我
无人共我 2020-12-09 08:41

I want to restrict the date picker of bootstrap from taking future date.I just want to enable the dates up to today only.How can i achieve this.

Here is my code

相关标签:
10条回答
  • 2020-12-09 09:30

    Set endDate property to +0d

    <script> 
        $(function() {
            $('.datepicker').datepicker({
                format: 'mm-dd-yyyy',
                endDate: '+0d',
                autoclose: true
            });
        });
    </script>
    

    FIDDLE

    0 讨论(0)
  • 2020-12-09 09:31

    Try this:

    var date=new Date();
    $('#datetimepicker').datetimepicker({
        format: 'MM/dd/yyyy',
        language: 'en',
        startDate : new Date('2015-01-01'),
        endDate :  date
    });
    
    0 讨论(0)
  • 2020-12-09 09:32

    This code worked for me..

    $('#txtTo').datepicker({
        dateFormat: "dd/MM/yy",
        changeMonth: true,
        changeYear: true,
        ignoreReadonly: true,
        maxDate: 'now'
    });
    
    0 讨论(0)
  • 2020-12-09 09:36

    Here is a demo of a working solution:

    http://jsfiddle.net/tjnicolaides/cjp7y/

    <script>
    $(function(){
        $('.datepicker').datepicker({
            format: 'mm-dd-yyyy',
            endDate: '+0d',
            autoclose: true
        });
    });
    </script>
    

    edit: the version of Bootstrap Datepicker that supports startDate and endDate is here: https://github.com/eternicode/bootstrap-datepicker

    The original project, which is the current top search result for the plugin, does not have that feature at this time: http://www.eyecon.ro/bootstrap-datepicker/

    0 讨论(0)
提交回复
热议问题