HTML DOM Textarea maxLength 속성은 HTML 문서에서 텍스트 영역 요소의 maxLength 속성 값을 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. maxLength 반환
object.maxLength
2. maxLength 수정
object.maxLength = “number”
HTML DOM Textarea maxLength 속성의 예를 살펴보겠습니다.
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
.show {
font-size: 1.5rem;
margin: 1rem 0;
}
</style>
<body>
<h1>DOM Textarea maxLength Property Demo</h1>
<textarea maxlength="50">Hi! I'm a text area element with some dummy text.</textarea>
<button onclick="set()" class="btn">Show Maximum Length</button>
<div class="show"></div>
<script>
function set() {
document.querySelector('.show').innerHTML = 'The maximum number of characters allowed in the above text area is ' + document.querySelector("textarea").maxLength;
}
</script>
</body>
</html> 출력

"최대 길이 표시를 클릭합니다. ” 버튼을 눌러 텍스트 영역 요소의 maxLength 속성 값을 표시합니다.
