创建具有自动调整大小的文本区域
textarea
clientHeight
textarea
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 ) };}