textarea自适应内容高度
程序员文章站
2022-04-18 09:30:10
...
转载网址:http://www.cnblogs.com/qubernet/p/6088509.html
$.fn.extend({
txtaAutoHeight: function () {
return this.each(function () {
var $this = $(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);
}
}
});
$(function(){
$("textarea").txtaAutoHeight();
});
下一篇: Numpy中的dot运算