使用javascript更改值时自动调整textarea的大小

时间:2015-02-08 14:18:12

标签: javascript jquery html css textarea

这是我的代码:

     <html>
            <head>
            <style>
            textarea{ 
              width: 30%; 
              min-width:30%; 
              max-width:30%; 
              overflow: hidden;
              height:10%; 
              min-height:10%;  
              max-height:10%;
              resize: none;
              white-space:pre;
            }
            </style>
            <script>
            function textAreaAdjust(o) {
                o.style.height = "1px";
                o.style.height = (25+o.scrollHeight)+"px";
            }
            function click1()
            {

                document.getElementById('text').value="Stack Overflow is a 
privately held website, the flagship site of the Stack Exchange Network,
[5][6] created in 2008 by Jeff Atwood and Joel Spolsky,[7][8] as a more open
 alternative to earlier Q&A sites such as Experts Exchange. The name for the
 website was chosen by voting in April 2008 by readers of Coding Horror, 
Atwood's popular programming blog.[9]";
                $("#text").focus();
            }
            </script>
            </head>
            <body>

            <textarea onkeyup="textAreaAdjust(this)" style="overflow:hidden" id="text"></textarea>
            <input type="button" onClick="click1()">
            </body>
            </html>

在此代码中,当我单击该按钮时,它应该显示我在textarea中的javascript中给出的内容。但我在这里给出的textarea是溢出的:隐藏的,所以它只显示了一些内容,其余内容隐藏起来。如何使所有内容可见。

需要你的所有建议。

0 个答案:

没有答案