2011-09-13 13 views
2

하루에 따라 jQueryUI 날짜 선택 도구의 maxDate를 동적으로 업데이트해야 할 필요가 있습니다. 현재, 아래에서 볼 수 있듯이 우리 팀이 금요일 - 일요일에만 문제를보고 할 수 있기 때문에 월요일 - 목요일을 사용 중지하는 데 사용되는 기능이 있습니다. 그래서 내가해야 할 일은 팀이 주말에 계속해서보고 할 수 있도록하기 위해서이다. 그러나 다음 주말에는 목요일까지는보고하지 않는다. 예를 들어, 오늘은 월요일이며, 팀은 지난 목요일 - 일요일의 문제에 대해서도보고 할 수 있으며 목요일까지 다음 주말에 하루를 선택할 수 없습니다. 이것이 가능한가? 이 같은jQuery UI datepicker maxdate

var fullDate = new Date(); 
    var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1);  

    $('#startdate').datepicker({ 
    maxDate: twoDigitMonth + "/" + fullDate.getDate() + "/" + fullDate.getFullYear(), 
    beforeShowDay: disableSpecificWeekDays 
    }); 


    function disableSpecificWeekDays(date) { 
    if((date.getDay()==0) || (date.getDay() == 5) || (date.getDay() == 6)){ 
     return [true]; 
    }else{ 
     return [false]; 
    } 
    } 

답변

2

뭔가가 당신을 위해 작동합니다 :

function getMaxDate() { 
    // Maximum date is today by default. 
    var maxDate = new Date(); 

    // Is today Thursday or greater (Thurs. - Sat.) 
    if (maxDate.getDay() >= 4) { 
     // Yes? Make the date today's date plus the difference between today and 
     // next Sunday 
     maxDate.setDate(
      maxDate.getDate() + (7 - maxDate.getDay())); 
    } 
    return maxDate; 
} 

$('#startdate').datepicker({ 
    maxDate: getMaxDate(), 
    beforeShowDay: disableSpecificWeekDays 
}); 

예 : 여기

내가 지금까지 가지고있는 코드는 기본적으로 http://jsfiddle.net/RxQB4/

, 함수를 작성하는 논리를 캡슐화합니다. datepicker를 초기화 할 때 해당 함수를 호출하여 최대 날짜를 검색합니다.