bootstrap datepicker today as default

前端 未结 12 2004
粉色の甜心
粉色の甜心 2020-12-24 04:32

I am using this bootstrap-datepicker for my datepicker. I\'d like the datepicker to choose \"today\" for start day or default day. I cannot figure out how to set \"today\"

相关标签:
12条回答
  • 2020-12-24 05:14

    I used this code

    $('#datePicker').datepicker({
                        format:'mm/dd/yyyy',
                    }).datepicker("setDate",'now');
    
    0 讨论(0)
  • 2020-12-24 05:20

    This should work:

    $("#datepicker").datepicker("setDate", new Date());

    And for autoclose (fiddle):

    $('#datepicker').datepicker({
            "setDate": new Date(),
            "autoclose": true
    });
    

    jQuery > datepicker API

    0 讨论(0)
  • 2020-12-24 05:22

    If none of the above option work, use the following :

    $(".datepicker").datepicker();
    $(".datepicker").datepicker("setDate", new Date());

    This worked for me.

    0 讨论(0)
  • 2020-12-24 05:25

    This question is about bootstrap date picker. But all of the above answers are for the jquery date picker. For Bootstrap datepicker, you just need to provide the defaut date in the value of the input element. Like this.

    <input class="form-control datepicker" value=" <?= date("Y-m-d") ?>">
    
    0 讨论(0)
  • 2020-12-24 05:27

    Its simple

    $(function() {
            $("#datePicker").datetimepicker({
                defaultDate:'now'
    
            });
        });
    

    This will set today as default

    0 讨论(0)
  • 2020-12-24 05:28

    Perfect Picker with current date and basic settings

            //Datepicker
            $('.datepicker').datepicker({
                autoclose: true,
                format: "yyyy-mm-dd",
                immediateUpdates: true,
                todayBtn: true,
                todayHighlight: true
            }).datepicker("setDate", "0");
    
    0 讨论(0)
提交回复
热议问题