2011-02-22 64 views
2

jQuery UI的日期选择器当窗体加载我想它已经拥有的当前日期 5天。因此,它2/22/2011,当页面加载文本框中的日期选择器属于应该显示3/1/2011。我知道如何默认的日期从当前日期设置为5天,但我需要它是在文本框中时,页面加载。自动设置负载

回答

5

实际上有一个更简单的方法。

$("#datepicker").datepicker(); 
$("#datepicker").datepicker("setDate", "+5d"); 

只是想通了。

1

我必须失去了一些东西,你会做这样的事情:

$(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); 
}); 

Working sample here here...