Jquery ui 在加载时自动设置jQuery UI日期选择器

Jquery ui 在加载时自动设置jQuery UI日期选择器,jquery-ui,options,jquery-ui-datepicker,Jquery Ui,Options,Jquery Ui Datepicker,当一个表单加载时,我希望它已经有当前日期加上5天。因此,2011年2月22日,当页面加载日期选择器所属的文本框时,应该显示2011年3月1日。我知道如何将默认日期设置为从当前日期算起的5天,但我需要在页面加载时将其放在文本框中。我必须缺少一些内容,您可以执行以下操作: $(function() { //set your date picker $('#test').datepicker(); //get the current date var yourDate

当一个表单加载时,我希望它已经有当前日期加上5天。因此,2011年2月22日,当页面加载日期选择器所属的文本框时,应该显示2011年3月1日。我知道如何将默认日期设置为从当前日期算起的5天,但我需要在页面加载时将其放在文本框中。

我必须缺少一些内容,您可以执行以下操作:

$(function() {
    //set your date picker
    $('#test').datepicker();

    //get the current date
    var yourDate = new Date();
    //set the current date to today + 5 days
    yourDate.setDate(yourDate.getDate() + 5)
    //format the date in the right format
    formatDate = (yourDate.getMonth() + 1) + '/' + yourDate.getDate() + '/' + yourDate.getFullYear();
    //set the input value
    $('#test').val(formatDate);
});

实际上有一种更简单的方法

$("#datepicker").datepicker();
$("#datepicker").datepicker("setDate", "+5d");
我刚想出来