HTML DOM Textarea readOnly 속성은 HTML 문서에 있는 텍스트 영역 요소의 내용을 읽기 전용으로 할지 여부를 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. 읽기 전용 반환
object.readOnly
2. 읽기 전용 추가
object.readOnly = true | false
HTML DOM Textarea readOnly 속성의 예를 살펴보겠습니다 -
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
background: lightseagreen;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
<body>
<h1>DOM Textarea readOnly Property Demo</h1>
<textarea rows="5" cols='20' name="I'm name attribute of textarea element">
Hi! I'm a text area element with some dummy text.
</textarea>
<button onclick="set()" class="btn">Toggle Read Only</button>
<script>
function set() {
var ta = document.querySelector("textarea");
if (ta.readOnly === true) {
ta.readOnly = false;
} else {
ta.readOnly = true;
}
}
</script>
</body>
</html> 출력

"읽기 전용 전환을 클릭합니다. ” 버튼을 눌러 텍스트 영역 요소의 readOnly 속성 값을 전환합니다.
