http://jsfiddle.net/hmelenok/WM6Gq/
<textarea type="text" id="title" rows="1">content</textarea>
#title { word-break: break-all; overflow: hidden; //IMPORTANT! 不加这一句会换行错误 }
$("#title").keydown(function () {
var element = this;
//setTimeout=0一定要写 window.setTimeout(function () { element.style.height = 'auto'; element.style.height = (element.scrollHeight) + 'px'; }, 0); });