天天看点

textarea文本域自适应内容高度

原先自己写的一个方法,在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/

继续阅读