jq实现textarea高度自适应

$.fn.extend({
txtaAutoHeight: function () {
return this.each(function () {
var $this = ( t h i s ) ; i f ( ! (this); if (! (this);if(!this.attr(‘initAttrH’)) {
$this.attr(‘initAttrH’, $this.outerHeight());
}
setAutoHeight(this).on(‘input’, function () {
setAutoHeight(this);
});
});
function setAutoHeight(elem) {
var $obj = $(elem);
return $obj.css({ height: $obj.attr(‘initAttrH’), ‘overflow-y’: ‘hidden’ }).height(elem.scrollHeight);
}
}
});
引用:
$(".textarea").txtaAutoHeight();

上一篇:HTML标签textarea去除红色下划线


下一篇:textarea如何实现高度自适应?