2011-02-22 38 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...