- $.fn.autoHeight = function(){
- function autoHeight(elem){
- elem.style.height = 'auto';
- elem.scrollTop = 0; //防抖动
- elem.style.height = elem.scrollHeight + 'px';
- }
- this.each(function(){
- autoHeight(this);
- $(this).on('keyup', function(){
- autoHeight(this);
- });
- });
- }
- $('textarea[autoHeight]').autoHeight();
- //该片段来自于http://www.codesnippet.cn/detail/2208201410290.html
来源: http://www.codesnippet.cn/detail/2208201410290.html