• 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   移动端都经过测试,没问题 放心用吧!

  • 相关阅读:
    vue之v-on
    垂直居中下
    垂直居中上
    vue之v-for
    vue之v-if和v-show
    vue之v-model
    vue之v-bind
    数学---目录
    【数学】证明题
    【计算机网络】应用层
  • 原文地址:https://www.cnblogs.com/purple04551/p/8075366.html
Copyright © 2020-2023  润新知