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/
精彩评论