채택완료

textarea 높이 질문

2025-03-09 (일) 21:18:11 2,176

textarea에 입력할때 처음 높이보다 내용이 많으면 스크롤이 생기는데

이걸 입력하는 양에 따라서 자동으로 높이가 커지게 가능한가요?

|

답변 1개

채택된 답변
+20 포인트
Copy
$(document).on('input','textarea',function () {
        var $this = $(this);
        if(!this.org_h){
            this.org_h = $this.outerHeight();
        }

        if(this.scrollHeight<this.org_h){
            return true;
        }

        this.style.height = 'auto';
        this.style.height = (this.scrollHeight) + 'px';
    })

답변을 작성하려면 로그인이 필요합니다.