1 jQuery.fn.extend({ 2 autoHeight: function(){ 3 return this.each(function(){ 4 var $this = jQuery(this); 5 if( !$this.attr('_initAdjustHeight') ){ 6 $this.attr('_initAdjustHeight', $this.outerHeight()); 7 } 8 _adjustH(this).on('input', function(){ 9 _adjustH(this);10 });11 });12 /**13 * 重置高度 14 * @param {Object} elem15 */16 function _adjustH(elem){17 var $obj = jQuery(elem);18 return $obj.CSS({height: $obj.attr('_initAdjustHeight'), 'overflow-y': 'hidden'})19 .height( elem.scrollHeight );20 }21 }22 });23 // 使用24 $(function(){25 $('textarea').autoHeight();26 });
新闻热点
疑难解答