-->

WEB资讯

您的当前位置:首页 > 资讯 > JS

textarea高度随着内容增加而增加

2022-10-26 13:45:15  来源:admin 点击:269

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


<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>

<script>

$(function(){

        $.fn.autoHeight = function(){    

        function autoHeight(elem){

            elem.style.height = 'auto';

            elem.scrollTop = 0; //防抖动

            elem.style.height = elem.scrollHeight+10 + 'px';

        }

        this.each(function(){

            autoHeight(this);

            $(this).on('keyup', function(){

                autoHeight(this);

            });

        });    

    }                

    $('textarea[autoHeight]').autoHeight();    

})

</script>


相关文章更多 >

© 2024版权所有 水水网

电话:171780793