现在的位置: 首页 > 综合 > 正文

textarea自适应高度

2013年08月25日 ⁄ 综合 ⁄ 共 281字 ⁄ 字号 评论关闭

项目中要求textarea自适应高度,在网上找到这个很好的方法 。记录下来以后备用。

function BodyOnLoad()
  {
      var textarea= document.getElementById("textarea");
      textarea.style.posHeight=textarea.scrollHeight;

  }

scrollHeight:获取对象的滚动高度。

posHeight:设置或获取以 height 标签属性指定的单位的对象高度。

把方法加在body的onload事件上

<body  onload = "BodyOnLoad();">

抱歉!评论已关闭.