textarea内容随高度自适应

$('textarea').each(function () {
  this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
}).on('input', function () {
  this.style.height = 'auto';
  this.style.height = (this.scrollHeight) + 'px';
});

参考:https://segmentfault.com/a/1190000009082811
posted @ 2018-07-27 11:59  叉歪叉  阅读(116)  评论(0编辑  收藏  举报