如何在 jquery UI 中为内联 Datepicker 设置日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16733395/
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 17:40:13  来源:igfitidea点击:

How to set date for an inline Datepicker in jquery UI?

javascriptjqueryjquery-uidatepicker

提问by adeneo

How to set date for an inline Datepickerin jqueryUI?

如何Datepicker在 jqueryUI 中为内联设置日期?

回答by adeneo

When initializing a datepicker, you'd use the defaultDateoption:

初始化日期选择器时,您将使用以下defaultDate选项:

$("#date").datepicker({
    defaultDate: '01/26/2014'
});

FIDDLE

小提琴

when changing the date later, you'd use setDatemethod:

稍后更改日期时,您将使用setDate方法:

$("#date").datepicker();
  // more code
$("#date").datepicker('setDate', '01/26/2014');

FIDDLE

小提琴

回答by Harry Ward

You can set multiple dates as well by using this:

您也可以使用以下方法设置多个日期:

    allBookings = []

    _.each(Session.get('thisGuide').bookings,function(e){
        allBookings.push(moment(e).format('MM/DD/YYYY'))
    })

    $('#datepicker').datepicker('setDates',allBookings)