$('textarea').each(function () {
//浏览器不兼容的情况下的获取方式
var oHeight=this.scrollHeight==0?$(this).height:this.scrollHeight;
this.setAttribute('style', 'height:' + oHeight + 'px;overflow-y:hidden;');
//正常情况下
this.setAttribute('style', 'height:' + this.scrollHeight + 'px;overflow-y:hidden;');
}).on('input', function () {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});
文章来源于:https://blog.csdn.net/qq_35607510/article/details/74331305