textarea自动增高并隐藏滚动条

<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">&nbsp;</pre>
<style type="text/css">
.autoheight{ padding: 5px; border:1px solid #666; line-height: 20px; font-size: 14px; }
</style>

posted @ 2012-09-25 16:34  justlancer  阅读(369)  评论(0编辑  收藏  举报