700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > jQuery实现textarea高度根据内容自适应

jQuery实现textarea高度根据内容自适应

时间:2021-01-26 15:39:14

相关推荐

jQuery实现textarea高度根据内容自适应

1 //jQuery实现textarea高度根据内容自适应2 $.fn.extend({3 txtaAutoHeight: function () {4 return this.each(function () {5 var $this = $(this);6 if (!$this.attr('initAttrH')) {7$this.attr('initAttrH', $this.outerHeight());8 }9 setAutoHeight(this).on('input', function () {10setAutoHeight(this);11 });12 });13 function setAutoHeight(elem) {14 var $obj = $(elem);15 return $obj.css({ height: $obj.attr('initAttrH'), 'overflow-y': 'hidden' }).height(elem.scrollHeight);16 }17 }18 });19 20 //调用21 $(function () {22 $("#txtaMain").txtaAutoHeight();23 });

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。