ITeye博客

textarea文本域自适应内容高度

bryant513 · 2012-08-27 11:50 · Web前端 · Markdown

原先自己写的一个方法,在textarea中用onpropertychange和oninput里监听调用

<script>

  function adjustHeight(blogId){

    var element = $("#comment_content_"+blogId);

    var minLimit = 24;

    if (!$.browser.mozilla){

      minLimit  += 4;

    }

    if (element[0].scrollHeight <= minLimit){

      element.css('height', ""+24);

      return false;

    }

    var newHeight = element[0].scrollHeight;

    newHeight = newHeight - 10;

    element.css('height', newHeight);

  } 

</script>

 

后来发现国外有人写好的jquery插件,代码量很少,功能也比较完善

http://bgrins.github.com/ExpandingTextareas/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。