textarea可以放大缩小

本文介绍了一种通过JavaScript实现的可动态调整大小的文本区域功能。用户可以通过点击“放大”或“缩小”按钮使文本区域的高度增加或减少,以此适应不同长度的输入内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
http://www.corange.cn//uploadfiles/080913_80051.jpg

<!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>corange-textarea可以放大缩小</title>
<style type="text/css">
/* Reset style */
* { margin:0; padding:0; word-break:break-all; }
body { background:#FFF; color:#333; font:12px/1.4em Helvetica, Arial, sans-serif; }
h1, h2, h3, h4, h5, h6 { font-size:1em; }
a { color:#333; text-decoration:none; }
a:hover { text-decoration:underline; }
ul, li { list-style:none; }
fieldset, img { border:none; }
input, textarea, select, button { font:12px Helvetica, Arial, sans-serif; }
.button { padding:0 10px; height: 22px; border: 1px solid; border-color: #EEE #999 #999 #EEE; background: #DDD; color: #333; line-height: 20px; cursor: pointer; margin-left:2px; }
.submit { padding:0 10px; height: 22px; border: 1px solid; border-color: #DDD #CC8305 #CC8305 #DDD; background: #FFA200; color: #FFF; line-height: 20px; letter-spacing: 1px; cursor: pointer; }
/* edit style */
#edit { width:300px; margin:50px; }
.edit_caption { width:100%; overflow:hidden; margin-bottom:1px; overflow:hidden; }
.edit_caption span { display:block; float:left; margin:0 1px; padding:4px 10px; background:#DDD; cursor:pointer; }
.edit_caption span:hover { background:#EEE; }
#edit textarea { width:300px; height:80px; margin:0; padding:0; }
</style>
<script type="text/javascript">
var addH=1;
function addHeight() {
if (!document.getElementById('comment_content')) return flase;
var comment = document.getElementById('comment_content');
var nowH = parseInt(comment.style.height);
if (nowH < 250) {
nowH+=2;
comment.style.height=nowH+"px";
addH++;
if (addH > 25){
addH=1;
} else {
window.setTimeout("addHeight()","10");
}
}
}
function minHeight() {
if (!document.getElementById('comment_content')) return flase;
var comment = document.getElementById('comment_content');
var nowH = parseInt(comment.style.height);
if (nowH > 50) {
nowH-=2;
comment.style.height=nowH+"px";
addH++;
if (addH > 25){
addH=1;
} else {
window.setTimeout("minHeight()","10");
}
}
}
</script>
</head>
<body>
<div id="edit">
<div class="edit_caption">
<span class="tool_bigger" onclick="addHeight()">放大</span>
<span class="tool_smaller" onclick="minHeight()">缩小</span>
</div>
<div><textarea id="comment_content" tabindex="1" rows="8" name="comment_content" style="height:100px"></textarea></div>
</div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值