开发者

Resize textbox everytime to fit the text length

In my ASP.NET page I have a text box which shows data which is bind to an (JavaScript) object variable. I want that textbox to resize everytime, the JavaScript object, e.g. result.title will change everytime.

Important: I want to fit the textbox exactly to the text 开发者_如何学JAVAlength inside.


Here is a great tutorial that teaches you how to make a jQuery plugin to do exactly what your talking about.


You could use onChange:

<textarea onChange="resize(this)"></textarea>

<script>
function resize(el) {
    el.cols = el.value.length;
}
</scrip>

Btw are you using Ajax?


Here's a jQuery plug-in: http://www.unwrongest.com/projects/elastic/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜