HTML DOM 입력 비밀번호 유형 속성은 type="password"인 입력 요소와 연결됩니다. 항상 입력 암호 요소에 대한 암호를 반환합니다.
구문
다음은 비밀번호 유형 속성의 구문입니다 -
passwordObject.type
예시
입력 암호 유형 속성에 대한 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<body>
<h1>password type property</h1>
PASSWORD: <input type="password" id="PASS1">
<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("PASS1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

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

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