js代码
$.fn.autoHeight = function () {
function autoHeight(elem) {
elem.style.height = 'auto';
elem.scrollTop = 0; //防抖动
elem.style.height = elem.scrollHeight + 'px';
}
this.each(function () {
autoHeight(this);
$(this).on('keyup', function () {
autoHeight(this);
});
});
}
$('textarea[autoHeight]').autoHeight();
HTML
<textarea autoHeight="true" > </textarea>
加上
autoHeight="true"
这一段即可
标签:jQuery,function,autoHeight,textarea,elem,height,适应 From: https://www.cnblogs.com/ouhouyi/p/16633570.html