首页 > 网站 > WEB开发 > 正文

textarea 高度自适应

2024-04-27 14:12:11
字体:
来源:转载
供稿:网友

textarea 高度自适应

 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         });


上一篇:(二)Angularjs

下一篇:(三)Angularjs

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表