首页 > 其他 > 详细

textarea的高度自适应

时间:2018-07-26 14:04:59      阅读:162      评论:0      收藏:0      [点我收藏+]

1.只读状态下的高度自适应

//maxHeight为最大高度
function autoTextarea(maxHeight){
        $.each($("textarea"), function(i, n){
            $("#textarea").css("overflow", "hidden");
            var _height = n.scrollHeight;
            $(n).height(_height);
            if( $(n).height() > maxHeight ){
                $(n).height(maxHeight);
                $("#textarea").css("overflow", "auto");
            }
        })
    }

效果图:

技术分享图片

 2.编辑状态下的高度自适应

$.each($("textarea"), function(i, n){
 $(n).height(n.scrollHeight);  $(n).on(
‘input‘,function(){ if(n.scrollHeight>n.offsetHeight){  $(n).height(n.scrollHeight)   } })
})

删除时,高度自适应还没有找到合适的方法(待续,如果你们有的话,可以给我留言)

textarea的高度自适应

原文:https://www.cnblogs.com/zsj-02-14/p/9371011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!