您可以通过设置为
1px,然后读取
scrollHeight属性来检查内容的高度:
function textareaAdjust(o) { o.style.height = "1px"; o.style.height = (25+o.scrollHeight)+"px";}<textarea onkeyup="textareaAdjust(this)" ></textarea>它可以在Firefox 3,IE 7,Safari,Opera和Chrome下运行。

您可以通过设置为
1px,然后读取
scrollHeight属性来检查内容的高度:
function textareaAdjust(o) { o.style.height = "1px"; o.style.height = (25+o.scrollHeight)+"px";}<textarea onkeyup="textareaAdjust(this)" ></textarea>它可以在Firefox 3,IE 7,Safari,Opera和Chrome下运行。