jquery实现textarea 高度自适应
之前给大家分享过用Javascript控制文本框textarea高度随内容自适应增长收缩,今天花了点时间换了种实现方法,总结一下
jQuery.fn.extend({
autoHeight:function(){
returnthis.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能够有所帮助。
热门推荐
10 小升初送给儿子祝福语简短
11 开丁大吉祝福语 简短
12 送祝福语给别人简短
13 送给新娘祝福语简短高级
14 元旦感恩祝福语简短大全
15 最佳元旦祝福语简短学校
16 手写妈妈生日祝福语简短
17 周末祝福语简短有内涵
18 高考加油祝福语简短押韵