2011-02-22 3 views
2

양식로드시 현재 날짜가 이고 일이되고 싶을 때. 그래서 2011 년 2 월 22 일, 페이지가 datepicker가 속한 텍스트 상자가로드 될 때 3/1/2011가 표시되어야합니다. 기본 날짜를 현재 날짜에서 5 일로 설정하는 방법을 알고 있지만 페이지가로드 될 때 텍스트 상자에 있어야합니다.로드시 자동으로 jQuery UI datepicker가 설정됩니다.

답변

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...

관련 문제