How to setup default date for jQuery inline datePicker?

爱⌒轻易说出口 提交于 2019-12-22 07:37:10

问题


I'm using this jQuery inline datePicker plugin sample but I don't know how to set up default date selected. Do you have any idea?


回答1:


$('.date-pick').datePicker({
    defaultDate: $.datepicker.parseDate("d m y", "31 8 2009")
})



回答2:


You will need to use the dpSetSelected method . I've added that into the code from the example page below:

$(function()
{
    $('.turn-me-into-datepicker')
        .datePicker({inline:true})
        .dpSetSelected('01/04/2010') // The string should be in Date.format
        .bind(
            'dateSelected',
            function(e, selectedDate, $td)
            {
                console.log('You selected ' + selectedDate);
            }
        );
});

As mentioned, if you have changed Date.format then you will need to ensure that the string is in the format you changed it to.




回答3:


Here: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePickerDefaultToday.html

$(function() {
     var date = new Date(); // replace with your date
     $('.date-pick').datePicker().val(date.asString()).trigger('change');
});

OR

Set date in your field:

<input class="date-pick" type="text" value="1/1/2009" />



回答4:


You can simply set value of that input box like $('#date-picker').val('22 Jun 2015');




回答5:


$("selector").datepicker('setDate', 'today');

To set UI widget and 'input' element.



来源:https://stackoverflow.com/questions/718599/how-to-setup-default-date-for-jquery-inline-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!