如何让 textarea 文本框 高度自动伸缩

个人博客:柚子青年。

本文主要讲的是如何让 textarea 文本框 自动伸缩

原理:每次输入文字后重置文本框默认高度 判断是否出现滚动条 动态修改高度 。

 

$(this).change(function () {
    this.style.height = 'height'; // height = textarea 默高度
    if (this.scrollHeight >= this.offsetHeight) { // 判断是否出现滚动条
        this.style.height = this.scrollHeight + 'px'; // 动态修改高度
    }
});

  



posted @ 2020-03-24 11:49  柚子青年。  阅读(661)  评论(0)    收藏  举报