textarea自适应内容高度

来源:互联网 发布:抠图软件 mac版 编辑:程序博客网 时间:2024/06/05 21:55

转载网址: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();            });
原创粉丝点击