다음 함수는 현재 브라우저가 기본 날짜 입력 <input type = "date"/>을 지원하면 true를 반환합니다.
https://htmldom.dev/check-if-the-native-date-input-is-supported
const isDateInputSupported = function() {
// Create new input element
const ele = document.createElement('input');
// Set the type attribute
ele.setAttribute('type', 'date');
const invalidValue = 'not-a-valid-date';
// Set an invalid value
ele.setAttribute('value', invalidValue);
// If the browser supports the date input,
// it won't have effect on the `value` attribute
// `ele.value` will be an empty string
//
// In the other case, the input is treated as normal text input
// and `ele.value` returns the original value
return ele.value !== invalidValue;
};
이 접근 방식을 사용하면 이메일, URL 등과 같은 다른 HTML 5 입력 유형을 확인할 수 있습니다.
등록된 댓글이 없습니다.