input高度固定,自动增长<br>
<input type="text" style="width:60;overflow-x:visible;overflow-y:visible;">
<br>
<br>
textarea 宽度固定,自动增高<br>
<textarea type="text" style="width:260;overflow-x:visible;overflow-y:visible;"></textarea>
html代码
<textarea id="content" onkeyup="adjustobjheight(this, 50);"></textarea>
js代码
<script language="网页特效" type="text/javascript">
function adjustobjheight(obj, defaultheight) {
if(obj.scrollheight > defaultheight) {
obj.style.height = obj.scrollheight + 'px';
} else {
obj.style.height = defaultheight + 'px';
}
}
window.onload = function() {
var obj = document.getelementsbytagname('textarea');
var len = obj.length;
for(var i = 0; i<len; i++)
adjustobjheight(obj[i], 50);
}
</script>
时间: 2024-10-21 10:41:30