2011-03-17 6 views
1

나는 양식을 만들고 있는데, 나는 그 사람에게 그들의 완전한 생일을 물어보고 싶습니다. 나는 그들이 태어난 날, 월, 일을 수집하고 있습니다. 나는이 개 질문이 : 그들은 자신의 출생의 달 2 월을 선택하는 경우, 그것은 "일"상자를 선택 29 일을 보여줄 수 있도록한 달의 일 수를 그 달을 기준으로 변경할 수 있습니까?

  1. 내가 그것을 만들 수 있습니다,하지만 그들은 월을 선택하면, 그것은 31를 표시합니다 "일"선택 상자에 일을 입력하십시오.

  2. 나는 그것을 제출하기 전에 그들의 정보를 보여주는 경고 상자가 있습니다. 지금은 그것들을 알려줍니다. 생년월일 : 월/일/년 (예 : 12/6/1970). 나이 : {Age} (예 : 나이 : 34 세)라고 말하면서 작성하도록 허용하는 코드가 있습니까?

고마워요!

답변

1

jQuery를 사용하는 경우 월/일 상황을 처리 할 $.datePicker을 볼 수 있습니다. (그리고 다른 옵션 here). 형식 지정의 경우 $().tmpl을 볼 수 있습니다.

일반 자바 스크립트 만 사용하는 경우 해당 월의 값을 확인하여 해당 월의 일 수를 설정할 수 있습니다. 이렇게 뭔가.

var month_select = document.getElementById("month"); 
month_select.onchange = function(){ 
    var month = month_select.options[mySelect.selectedIndex].value, days; 
    if(month == 2){ // Feb 
    days = 28; // or 29 if you want to check for the leap year as well 
    }else if(month % 2){ // if the month is "even" 
    days = month <= 7 : 30 : 31; // if the month is odd and between Jan - July, then it will have 30 days, otherwise it will have 31 
    }else{ 
    days = month <= 7 : 31 : 30; // similar to above but when months are odd 
    } 

    // update days via DOM here 
    var options = month_select.options, options_length = options.length; 
    if(days > options_length){ // if it has options in days then the currently selected month, then remove some 

    }else if(days < options_length){ // if it has less, then add 

    } // if it has the same number, then don't do anything 
} 
관련 문제