textarea高度自适应

2019-12-03  本文已影响0人  小小_chao
$(document).ready(function () {
  $('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';
  });
})

代码来源于:http://www.softwhy.com/article-9626-1.html
注:
1.“蚂蚁部落(http://www.softwhy.com/qiduan/)”网站有很多关于前端的教程;
2.https://blog.csdn.net/cindy647/article/details/87886344此链接有关于输入框input、textarea的零碎知识点;
大家可以前往查阅哦~

上一篇 下一篇

猜你喜欢

热点阅读