如何为 jQuery 内联 datePicker 设置默认日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/718599/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 09:38:00  来源:igfitidea点击:

How to setup default date for jQuery inline datePicker?

jquerydatepicker

提问by dole doug

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

我正在使用这个jQuery 内联 datePicker插件示例,但我不知道如何设置选择的默认日期。你有什么主意吗?

回答by Philippe Rathé

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

回答by vitch

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

您将需要使用该dpSetSelected方法。我已将其添加到以下示例页面的代码中:

$(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.formatthen you will need to ensure that the string is in the format you changed it to.

如前所述,如果您更改了 Date.format,那么您需要确保字符串采用您更改的格式。

回答by Konstantin Tarkus

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

在这里: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" />

回答by Deepak Ram

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

您可以简单地设置该输入框的值,如 $('#date-picker').val('22 Jun 2015');

回答by ats

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

To set UI widget and 'input' element.

设置 UI 小部件和“输入”元素。