`
bryant513
  • 浏览: 6042 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
最近访客 更多访客>>
社区版块
存档分类
最新评论

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/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics