HTML DOM Button disabled 속성은
구문
다음은 −
의 구문입니다.비활성화된 속성 설정 -
buttonObject.disabled = true|false
여기에서 true|false는 주어진 입력 버튼을 비활성화할지 여부를 지정합니다.
- 사실 - 버튼이 비활성화됩니다.
- 거짓 - 버튼은 비활성화되지 않습니다.
버튼 비활성화 속성의 예를 살펴보겠습니다 -
예시
<!DOCTYPE html>
<html>
<body>
<button id="Button1">BUTTON</button>
<p>Click the below button to disable the above button.</p>
<button onclick="buttonDis()">CLICK IT</button>
<p id="Sample">
<script>
function buttonDis() {
document.getElementById("Button1").disabled = true;
var x=document.getElementById("Button1").disabled;
document.getElementById("Sample").innerHTML = "Button disabled is "+x;
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

CLICK IT 버튼을 클릭하면 -

위의 예에서 -
id가 "Button1"인 버튼을 만들었으며 버튼은 기본적으로 활성화되어 있습니다.
<button id="Button1">BUTTON</button>
그런 다음 클릭 시 buttonDis() 메서드를 실행하는 CLICK IT 버튼을 만들었습니다.
<button onclick="buttonDis()">CLICK IT</button>
buttonDis() 메서드는 id "button1"로 버튼 요소를 가져오고 비활성화된 속성을 true로 설정합니다. 버튼을 비활성화하면 비활성화된 값(true 또는 false)이 변수 x에 할당되고 id가 "Sample"인 단락에 표시됩니다.
function buttonDis() {
document.getElementById("Button1").disabled = true;
var x=document.getElementById("Button1").disabled;
document.getElementById("Sample").innerHTML = "Button disabled is "+x;
}