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

HTML DOM 입력 라디오 유형 속성

<시간/>

HTML DOM 입력 라디오 유형 속성은 type="radio"인 입력 요소와 연결됩니다. 입력 라디오 요소에 대해 항상 라디오를 반환합니다.

구문

다음은 라디오 유형 속성의 구문입니다 -

radioObject.type

예시

라디오 유형 속성에 대한 예를 살펴보겠습니다 -

<!DOCTYPE html>
<html>
<body>
<h1>Input radio type Property</h1>
<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
<br>
</form>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="radioType()">GET Type</button>
<p id="Sample"></p>
<script>
   function radioType() {
      var P=document.getElementById("Mango").type;
      document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
   }
</script>
</body>
</html>

출력

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

HTML DOM 입력 라디오 유형 속성

GET Type 버튼 클릭 시 -

HTML DOM 입력 라디오 유형 속성

먼저 type=”radio”, name=”fruits”, id=”Mango” −

형식의 입력 요소를 생성했습니다.
<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>

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

<button type=”button” onclick="radioType()">GET Type</button>

radioType() 메서드는 getElementById() 메서드를 사용하여 입력 요소를 가져오고 해당 유형 속성 값을 변수 P에 할당합니다. 그런 다음 이 변수는 innerHTML 속성 -

을 사용하여 id가 "Sample"인 단락에 표시됩니다.
function getType() {
   var P = document.getElementById("Mango").type;
   document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}