用 jquery 做的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>文字區塊自動高度</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($) {
$("textarea.AutoHeight").css("overflow","hidden").bind("keydown keyup", function(){
$(this).height('0px').height($(this).prop("scrollHeight")+"px");
}).keydown();
});
</script>
</head>
<body>
<textarea class="AutoHeight"></textarea>
<textarea class="AutoHeight"></textarea>
<textarea class="AutoHeight"></textarea>
</body>
</html>
沒有留言:
張貼留言