textarea多行文本框自适应高度

Posted 黑暗之光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了textarea多行文本框自适应高度相关的知识,希望对你有一定的参考价值。

<script src="https://cdn.bootcss.com/jquery/1.8.1/jquery.js"></script>
<script>
    $(function(){
        function autoHeight(ele){
            var $this = $(ele);
            $this.css({‘height‘:‘20px‘,‘overflow-y‘:‘hidden‘}).height(ele.scrollHeight);
            if(parseInt($this.height())>60){
                $this.height(60);
            }
        }
        $(‘.text‘).on(‘input propertychange‘,function(){
            autoHeight(this);
        })
    $(‘.text‘).trigger("input");
$(‘.text‘).trigger("propertychange");
})
 }) </script>
<textarea name="message"  class="text"></textarea>

 

以上是关于textarea多行文本框自适应高度的主要内容,如果未能解决你的问题,请参考以下文章