0
편집 : 내 질문에 잘못되었습니다. 필요한 DOB 필드를 비워두면 사용자 DOB가 17 세 이상인 경우에만 말하고 싶은 'Welcome'
이라고 표시됩니다. 환영 메시지가 나온 후 필요한 DOB 필드를 채우라고 알려줍니다. DOB가 입력되지 않은데도 여전히 환영받는 이유는 무엇입니까?자바 스크립트 - 필수 입력란이 비어있는 양식 제출
출산 필드의 날짜 생년월일 : 출생 확인 기능의
<input type="text" name="Date" id="dateof" placeholder="YYYY-MM-DD" title="Enter your date of birth in the form YYYY-MM-DD" required /><br/><br/>
날짜
var minAge = 17;
var today = new Date()
function calcAge(birthDate, todaysDate) {
todaysDate = new Date(today);
var givenDOB = document.getElementById('dateof').value; /*date of birth entered*/
var birthDate = new Date(givenDOB);
var years = (todaysDate.getFullYear() - birthDate.getFullYear());
if (todaysDate.getMonth() < birthDate.getMonth() ||
todaysDate.getMonth() == birthDate.getMonth() && todaysDate.getDate() < birthDate.getDate()) {
years--;
}
return years;
}
function setAge() {
var age = calcAge();
if (age < minAge) {
alert("Sorry, the minimum age is 17!");
} else
alert("Welcome!");
}
아마도 브라우저가 필요하거나 필수 입력을 시도하십시오. –
모든 양식 코드를 공유 할 수 있습니까? –