HTML DOM Textarea 자동 초점 속성은 페이지가 로드될 때 텍스트 영역에 자동으로 초점이 맞춰져야 하는지 여부를 반환하고 수정합니다.
구문
다음은 구문입니다 -
1. 자동 초점 반환
object.autofocus
2. 자동 초점 수정
object.autofocus = true | false
HTML DOM Textarea 자동 초점 속성의 예를 살펴보겠습니다.
예시
<!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;
}
</style>
<body>
<h1>DOM Textarea autofocus Property Demo</h1>
<textarea autofocus>Hi! I'm a text area element with some dummy text.</textarea>
<button onclick="set()" class="btn">Disable Autofocus</button>
<script>
function set() {
document.querySelector("textarea").autofocus = false;
}
</script>
</body>
</html> 출력

"자동 초점 비활성화를 클릭합니다. " 버튼을 눌러 텍스트 영역 요소에서 자동 초점을 비활성화합니다. 이제 커서가 표시되지 않습니다.
