为了将来参考,还有一个没有jQuery的解决方案-仅使包装div样式包含overflow:hidden
并使用以下JavaScript两行代码:
// get the width of the textarea minus scrollbar
var textareaWidth = document.getElementById("textarea").scrollWidth;
// width of our wrapper equals width of the inner part of the textarea
document.getElementById("wrapper").style.width = textareaWidth + "px";