textarea高度自适应, textarea随内容的增多自动增加高度。注意onpropertychange不能加this.style.height='0px';,在IE下会出现 Stack overflow at line:0 错误。
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>textarea高度自适应</title>
</head>
<body>
<textarea style="height:18px;line-hieght:18px;padding:3px;width:200px;overflow:hidden;resize:none" onpropertychange="this.style.height=this.scrollHeight + 'px'" oninput="this.style.height='0px';this.style.height=this.scrollHeight + 'px'" ></textarea>
</body>
</html>
demo:
回复该留言