<script type="text/javascript">
function autoHeight(self){
$('#testbox').html($(self).val());
var height = $('#testbox').outerHeight();
if(height<20){
return;
}
$(self).scroll(function(){
$(self).scrollTop(0);
});
$(self).outerHeight(height);
}
</script>
<textarea class="autoheight" id="tValue" style="overflow-y:hidden; height:20px;" onpropertychange="autoHeight(this)" oninput="autoHeight(this)" onkeyup="autoHeight(this)" onkeydown="autoHeight(this)" ></textarea>
<pre class="autoheight" style="" id="testbox"> </pre>
<style type="text/css">
.autoheight{ padding: 5px; border:1px solid #666; line-height: 20px; font-size: 14px; }
</style>
转载于:https://www.cnblogs.com/justlancer/archive/2012/09/25/2701762.html