zoukankan      html  css  js  c++  java
  • textarea高度自适应,随着内容增加高度增加

    $(function(){
            $.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();    
    })

    页面中的textarea直接加属性就行

    <textarea  autoHeight="true" readonly="readonly" > </textarea>

    pc   移动端都经过测试,没问题 放心用吧!

  • 相关阅读:
    第十三周
    意见评论
    第十二周
    冲刺10
    冲刺9
    冲刺8
    团队冲刺第二十二天-KeepRunningAPP
    找水王
    第十四周总结
    搜狗输入法评价
  • 原文地址:https://www.cnblogs.com/purple04551/p/8075366.html
Copyright © 2011-2022 走看看