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

HTML DOM 입력 라디오 비활성화 속성

<시간/>

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

구문

다음은 −

구문입니다.

비활성화된 속성을 설정합니다.

radioObject.disabled = true|false;

여기에서 true=라디오 버튼이 비활성화되어 있고 false=라디오 버튼이 비활성화되어 있지 않습니다. 기본적으로 거짓입니다.

예시

입력 라디오 비활성화 속성의 예를 살펴보겠습니다. -

<!DOCTYPE html>
<html>
<body>
<h1>Input radio disabled Property</h1>
<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>
<p>Disable the above radio button by clicking on the DISABLE button</p>
<button type="button" onclick="disableRadio()">DISABLE</button>
<p id="Sample"></p>
<script>
   function disableRadio() {
      document.getElementById("Mango").disabled=true;
      document.getElementById("Sample").innerHTML = "The radio button is now disabled" ;
   }
</script>
</body>
</html>

출력

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

HTML DOM 입력 라디오 비활성화 속성

비활성화 버튼 클릭 시 -

HTML DOM 입력 라디오 비활성화 속성

위의 예에서 -

먼저 type=”radio”, name=”fruits”, id=”Mango”인 양식 안에 입력 요소를 만들었습니다.

<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>

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

<button type=”button” onclick="disableRadio()">DISABLE</button>

disableRadio() 메서드는 getElementById() 메서드를 사용하여 라디오 유형의 입력 요소를 가져오고 비활성화된 속성을 true로 설정합니다. 이렇게 하면 라디오 버튼이 회색으로 표시되고 사용자는 더 이상 이 버튼과 상호 작용할 수 없습니다.

function disableRadio() {
   document.getElementById("Mango").disabled=true;
   document.getElementById("Sample").innerHTML = "The radio button is now disabled" ;
}