chenfahui'Blog

陈发辉的个人主页 chenfahui.cn

« 判断浏览器否为IE6jquery离开页面提示 »

textarea高度自适应

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: 

  • 相关文章:

1

发表评论

网站分类

文章归档

Tags

Powered By Z-Blog 1.8 Walle Build 100427
Copyright 2009-2012 chenfahui.cn. Some Rights Reserved.www.chenfahui.cn网站PR查询