注册 登录
编程论坛 ASP.NET技术论坛

js如何让文本框自动增高?

hhy420459674 发布于 2011-12-29 17:02, 808 次点击
我在做邮箱发送邮件的时候,当选择的收件人过多的时候,我希望文本框能够像QQ邮箱那样自动增高,请问各位高手 该咋个实现啊?
1 回复
#2
xueyifeng2011-12-30 13:13
程序代码:
<html>
<head>
<title>1</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<textarea id="txt" cols="10" rows="1" style="overflow:hidden;" onKeyUp="autoAreaHeight(this,parseInt(this.cols)*parseInt(this.rows),10)" ></textarea >

<script type="text/javascript">
function autoAreaHeight(area,maxLength,cols){
    if(area.value.length>maxLength)
    {
        var rows = parseInt(area.getAttribute("rows"));
        area.setAttribute("rows",rows+1);
    }
}
</script>
</body>
</html>
1