天天看點

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/

繼續閱讀