码迷,mamicode.com
首页 > 其他好文 > 详细

textarea多行文本框自适应高度

时间:2018-01-10 11:24:49      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:20px   pos   script   class   color   textarea   style   this   boot   

<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多行文本框自适应高度

标签:20px   pos   script   class   color   textarea   style   this   boot   

原文地址:https://www.cnblogs.com/jkingdom/p/8243984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!