87,915
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<HTML>
<HEAD>
<TITLE>无滚动条Textarea自动适用高度</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<textarea id="test" rows="1" onpropertychange="this.style.height=this.scrollHeight+'px';" oninput="this.style.height=this.scrollHeight+'px';" style="overflow:hidden;height:16px;"></textarea>
</BODY>
</HTML>
<?xml version="1.0" encoding="gb2312"?>
<html>
<head>
<meta http-equiv="Content-Type" Content="text/html; charset=gb2312"/>
<meta http-equiv="Content-Script-Type" Content="text/javascript"/>
<meta http-equiv="Content-Style-Type" content="text/css"/>
<meta http-equiv="Author" content="Langtse"/>
<title>动态调整表单文本区高度</title>
<style>
*{border:0px solid silver;font-size:12px;padding:0px;margin:0px;}
body{padding:32px;}
textarea{border-width:1px;width:320px;overflow:hidden;padding:0px 12px;}
</style>
<script>
var oTimer,oText;
function getId(sId){return document.getElementById('oText');}
function fitOnce(){oText.style.height=oText.scrollHeight;}
function fitLoop(){oTimer=window.setInterval("fitOnce();",1);}
</script>
</head>
<body onload="oText=getId('oText');fitOnce();">
<form>
<textarea id="oText" onkeydown="fitLoop();" onchange="fitLoop();"
onblur="fitOnce();window.clearInterval(oTimer);">
动态调整表单文本区高度
全面兼容Avant,火狐Firefox,微软IE,遨游Maxthon,Opera
测试平台:
IE7.0;
Firefox2.0;
Avant11.5;
Maxthon2.1.3;
Opera9.51;
</textarea>
</form>
</body>
</html>