复制代码 代码如下:
jquery.fn.extend({
autoheight: function(){
return this.each(function(){
var $this = jquery(this);
if( !$this.attr('_initadjustheight') ){
$this.attr('_initadjustheight', $this.outerheight());
}
_adjusth(this).on('input', function(){
_adjusth(this);
});
});
/**
* 重置高度
* @param {object} elem
*/
function _adjusth(elem){
var $obj = jquery(elem);
return $obj.css({height: $obj.attr('_initadjustheight'), 'overflow-y': 'hidden'})
.height( elem.scrollheight );
}
}
});
// 使用
$(function(){
$('textarea').autoheight();
});
以上就是本文所述的全部内容了,希望对大家学习jquery能够有所帮助。
