可能的重复:
使用原型自动调整文本区域大小 https://stackoverflow.com/questions/7477/autosizing-textarea-using-prototype
如何根据用户放入文本区域的行数更改文本区域的高度?
对于下面的示例,如果用户将文本区域中的文本更改为多行文本,则文本区域将在其自身上放置一个滚动条,而不是更改其高度以适应行数。
<textarea>
This is the default text that will be displayed in the browser. When you change this text and add more lines to it the browser will not change the height of the textarea that this text is in rather it will add a scroll bar, which is not what I want.
<textarea>
<textarea onkeyup="autoSize(this);"></textarea>
function autoSize(ele)
{
ele.style.height = 'auto';
var newHeight = (ele.scrollHeight > 32 ? ele.scrollHeight : 32);
ele.style.height = newHeight.toString() + 'px';
}
调整“32”以匹配行高作为练习。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)