Computer >> 컴퓨터 >  >> 프로그램 작성 >> HTML

HTML DOM 입력 비밀번호 비활성화 속성

<시간/>

HTML DOM 입력 비밀번호 비활성화 속성은 비밀번호 필드의 비활성화 여부를 설정하거나 반환하는 데 사용됩니다. 요소가 비활성화되어야 함을 나타내는 true와 그렇지 않으면 false인 부울 값을 사용합니다. disabled 속성은 기본적으로 false로 설정됩니다. 비활성화된 요소는 기본적으로 회색으로 표시되며 클릭할 수 없습니다.

구문

다음은 −

의 구문입니다.

비활성화된 속성 설정 -

passwordObject.disabled = true|false;

여기에서 true=password 필드가 비활성화되고 false=password 필드가 비활성화되지 않습니다. 기본적으로 거짓입니다.

예시

Input password disabled 속성에 대한 예를 살펴보겠습니다. -

<!DOCTYPE html>
<html>
<body>
<h1>Input Password disabled Property</h1>
Password: <input type="password" id="PASS">
<p>Disable the above password field by clicking on the DISABLE button</p>
<button type="button" onclick="disablePass()">DISABLE</button>
<p id="Sample"></p>
<script>
   function disablePass() {
      document.getElementById("PASS").disabled=true;
      document.getElementById("Sample").innerHTML = "The password field is now disabled" ;
   }
</script>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

비활성화 버튼 클릭 시 -

HTML DOM 입력 비밀번호 비활성화 속성

"사용 안 함" 버튼을 클릭하면 -

HTML DOM 입력 비밀번호 비활성화 속성

위의 예에서 -

먼저 ID가 "PASS"인 입력 암호 필드를 만들었으며 비활성화된 속성은 기본적으로 FALSE -

로 설정되어 있습니다.
Password: <input type="password" id="PASS" value="abcd123">

그런 다음 사용자가 클릭할 때 disablePass() 메서드를 실행하는 DISABLE 버튼을 만들었습니다.

<button type="button" onclick="disablePass()">DISABLE</button>

disablePass() 메서드는 getElementById() 메서드를 사용하여 암호 유형의 입력 필드를 가져오고 비활성화된 속성을 true로 설정합니다. 이렇게 하면 암호 필드가 비활성화되고 회색으로 표시됩니다. 그런 다음 암호 필드가 이제 비활성화되었음을 나타내는 id가 "Sample"인 단락의 innerHTML 속성을 사용하여 메시지를 표시합니다. -

function disablePass() {
   document.getElementById("PASS").disabled=true;
   document.getElementById("Sample").innerHTML = "The password field is now disabled" ;
}