HTML DOM 입력 숫자 유형 속성은 해당 유형이 "숫자"인 입력 요소와 연결됩니다. 입력된 숫자 요소에 대해 항상 숫자를 반환합니다.
구문
다음은 숫자 유형 속성의 구문입니다 -
numberObject.type
예시
HTML DOM 입력 숫자 유형 속성의 예를 살펴보겠습니다. -
<!DOCTYPE html>
<html>
<body>
<h1>Input Number type property</h1>
PHONE NO: <input type="number" id="NUMBER1">
<p>Get the above element type by clicking the below button</p>
<button onclick="getType()">Get Type</button>
<p id="Sample"></p>
<script>
function getType() {
var t = document.getElementById("NUMBER1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"유형 가져오기" 버튼 클릭 시 -

위의 예에서 -
유형 번호와 ID가 "NUMBER1"로 설정된 입력 필드를 만들었습니다.
PHONE NO: <input type="number" id="NUMBER1">
그런 다음 사용자가 클릭할 때 getType() 메서드를 실행하는 "Get Type" 버튼을 만들었습니다.
<button onclick="getType()">Get Type</button>
getType() 메서드는 getElementById() 메서드를 사용하여 입력 요소를 가져오고 해당 유형 속성 값을 변수 t에 할당합니다. 그런 다음 이 변수는 innerHTML 속성을 사용하여 id가 "Sample"인 단락에 표시됩니다 -
function getType() {
var t = document.getElementById("NUMBER1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
}