다음은 JavaScript를 사용하여 자동 크기 조정 텍스트 영역을 만드는 코드입니다 -
예시
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<h1>Creating auto-resize text area</h1>
<textarea class="resizeArea"></textarea>
<script>
let BtnEle = document.querySelector(".Btn");
let addrEle = document.querySelectorAll(".addr");
let resizeEle = document.querySelector(".resizeArea");
resizeEle.addEventListener("input", resizeTextArea, false);
function resizeTextArea() {
this.style.height = "auto";
this.style.height = this.scrollHeight + "px";
}
</script>
</body>
</html> 출력

텍스트 영역에 텍스트를 붙여넣으면 영역이 다음과 같이 확장됩니다. -
