如题,请问各位大侠如何实现。根据文本框里的值的宽度自动变化文本框的宽度。

解决方案 »

  1.   

    <html>
    <body>
    <input type="text" id="content" size="10" onpropertychange="resize(this)" oninput="resize(this)" />
    <span id="copy" style="visibility:hidden"></span>
    <script>
    var x0 = document.getElementById('content').offsetWidth;
    function resize(obj){
    var copy = document.getElementById('copy');
    copy.innerHTML = obj.value;
    obj.style.width = x0 + copy.offsetWidth + "px";
    }
    </script>
    </body>
    </html>