代码改变世界

textarea自动调节高度

2014-03-13 10:07  ゞ蓦然灬淺笑ゞ  阅读(264)  评论(0编辑  收藏  举报

js代码

  textareaHeight:function(){

    $("textarea").bind("input propertychange focus", function () {

              this.style.posHeight = this.scrollHeight;

    });

    $("textarea").each(function () {

             this.style.posHeight = this.scrollHeight;

    });

  }

HTML代码

<textarea style="width:100%;">

  IE支持 onPropertyChange 火狐支持oninput
  IE支持 onPropertyChange 火狐支持oninput

</textarea>