HTML DOM 입력 확인란 이름 속성은 입력 확인란의 이름 속성 값인 문자열을 반환합니다. 사용자는 새 문자열로 설정할 수도 있습니다.
구문
다음은 구문입니다 -
- 문자열 값 반환
inputCheckboxObject.name
- 이름 설정 문자열 값에 대한 속성
inputCheckboxObject.name = ‘String’
예시
Input Checkbox name 속성의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<title>Name Attribute of Checkbox</title>
</head>
<body>
<form id="Form">
<div>
Enable new name: <input id="formID" type="checkbox" name="formID">
</div>
</form>
<button onclick="getFormID()">Change Name Attribute</button>
<div id="nameAttr"></div>
<script>
function getFormID(){
var oldNameAttr = document.getElementById("formID");
var newNameAttr = document.getElementById("nameAttr");
if(oldNameAttr.checked == true){
oldNameAttr.name = 'newFormID';
newNameAttr.textContent = 'Updated value of name attribute: '+oldNameAttr.name;
} else {
newNameAttr.textContent = 'Check the checkbox'+ ', current value of name attribute: '+oldNameAttr.name ;
}
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -
'새 이름 사용'을 확인하기 전에 체크박스 -

'새 이름 사용'을 확인한 후 체크박스 -
