textarea输入框随内容撑开高度


原文链接

 

方法一(jquery):

$('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';
});

方法二:

function setHeight(element) {
  $(element).css({'height':'auto','overflow-y':'hidden'}).height(element.scrollHeight);
}
$('textarea').each(function () {
  setHeight(this);
}).on('input', function () {
  setHeight(this);
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 textarea内容自动撑开高度,实现高度自适应 html中用div代替textarea实现输入框高度随输入内容变化 uni-app textarea内容自动换行,输入框高度自适应 自适应高度输入框(contenteditable/textarea) textarea 文本框根据输入内容自适应高度 使用div模拟textarea,实现文本输入框高度自适应(附:js控制textarea实现文本输入框高度自适应) 移动端input/textarea输入框光标高度兼容及其他事项