源代码:
23:03文章更新:
感谢alucelx同学再次给力的帮助,大大简化了方法,更新代码为0.2版本,同时解决了兼容opera浏览器,至此全兼容ie6+与现代浏览器!
在线演示:
autotextarea.js
测试代码:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>文本框根据输入内容自适应高度</title>
<style type="text/css">
#textarea { font: 1.4em/1.8em arial; overflow: hidden; width: 550px; height: 6em; padding:10px; }
</style>
<script src="autotextarea.js"></script>
</head>
<body style="background:#fbfcfd url(http://goo.gl/klszx);">
<textarea id="textarea"></textarea>
<script>
var text = document.getelementbyid("textarea"),
tip = '想写点什么..';
autotextarea(text);// 调用
text.value = tip;
text.onfocus = function () {
if (text.value === tip) text.value = '';
};
text.onblur = function () {
if (text.value === '') text.value = tip;
};
</script>
</body>
</html>
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论