Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
valueAsNumber 속성은 HTMLInputElement 인터페이스에서 <input> 요소의 현재 값을 숫자로 반환하고 숫자로 변환할 수 없는 경우 NaN을 반환합니다.
또한, 특정 조건에 따라 속성을 직접 설정하여 기본 숫자 값을 지정할 수 있습니다.
요소의 값을 나타내는 숫자이며 숫자로 변환할 수 없는 경우 NaN
이번 예제에서는 number 입력 값이 변경될 때 로그에 현재 값이 표시됩니다.
number 타입의 <input>, 이와 연관된 <label> 그리고 출력을 위한 <pre> 컨테이너를 포함하고 있습니다.
<pre> 요소의 innerText는 change 이벤트가 발생할 때마다 <input>의 현재 값으로 업데이트 됩니다.
위젯에서 숫자를 삭제하면 결과는 NaN이 됩니다.
이번 예제에서는 datetime-local 타입의 <input>에서 valueAsNumber 속성을 보여줍니다.
datetime-local 타입의 <input>을 포함하고 있습니다.
날짜와 시간이 선택되지 않으면 빈 문자열이 NaN으로 처리됩니다. 시간이 선택될 때마다 change 이벤트가 발생하며, <pre> 콘텐츠가 업데이트 되어 폼 컨트롤의 HTMLInputElement.value 값을 숫자 값과 비교하여 표시됩니다.
| HTML # dom-input-valueasnumber-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 5월 29일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.