码迷,mamicode.com
首页 > 其他好文 > 详细

textarea输入框随内容撑开高度

时间:2018-10-09 11:42:31      阅读:350      评论:0      收藏:0      [点我收藏+]

标签:article   输入框   链接   attr   csdn   input   css   lan   height   

原文链接

 

方法一(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);
});

textarea输入框随内容撑开高度

标签:article   输入框   链接   attr   csdn   input   css   lan   height   

原文地址:https://www.cnblogs.com/GoCircle/p/9759252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!