<style type="text/css">
        #shadow, #text { font: 12px/16px Arial; width: 200px; overflow: hidden; height: 16px; }
        #shadow { position: absolute; border-width: 0px; padding: 0px; visibility: hidden; }
        #text { resize: none; }
    </style>
    <script type="text/javascript">
        /*
      by VILIC VANE
            Web www.vilic.info
            Email i@vilic.info
        */
        window.onload = function () {
            var text = document.getElementById("text"); //用户看到的文本框
            var shadow = document.getElementById("shadow"); //隐藏的文本框
            text.oninput = //非IE的
            text.onpropertychange = //IE的
            onchange;
            
            function onchange() {
                shadow.value = text.value;
                setHeight();
                setTimeout(setHeight, 0); //针对IE 6/7/8的延迟, 否则有时会有一个字符的出入
                function setHeight() { text.style.height = shadow.scrollHeight + "px"; }
            }
        };
    </script>
<body>
    <textarea ></textarea>
    <textarea ></textarea>
</body>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2021-11-27
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
猜你喜欢
  • 2022-12-23
  • 2021-12-22
  • 2021-09-18
  • 2021-09-24
  • 2022-01-30
  • 2022-12-23
  • 2021-12-31
相关资源
相似解决方案