創(chuàng)建具有自動調(diào)整大小的文本區(qū)域有關(guān)于這件事的另一條線索我試過了。但是有一個問題:textarea如果刪除內(nèi)容不會縮小。我找不到任何方法把它縮小到正確的尺寸clientHeight值的完整大小返回。textarea而不是它的內(nèi)容。該頁的代碼如下:function FitToContent(id, maxHeight){
var text = id && id.style ? id : document.getElementById(id);
if ( !text )
return;
var adjustedHeight = text.clientHeight;
if ( !maxHeight || maxHeight > adjustedHeight )
{
adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);
if ( maxHeight )
adjustedHeight = Math.min(maxHeight, adjustedHeight);
if ( adjustedHeight > text.clientHeight )
text.style.height = adjustedHeight + "px";
}}window.onload = function() {
document.getElementById("ta").onkeyup = function() {
FitToContent( this, 500 )
};}
創(chuàng)建具有自動調(diào)整大小的文本區(qū)域
斯蒂芬大帝
2019-06-09 15:57:25