实现js 动态加载textarea内容的高度

在很多时候,我们需要用textarea来显示内容,因为这样可以不必去处理textarea填写的数据,显示的时候不用在转换,但是高度是一个问题。昨天碰上了就研究了一下,发现不是很难,直接上代码了。

//定义css,无边框,不可修改,选中的时候取消边线.自动滚动条,不可改变大小
.text_readonly{zoom:1;outline:0;line-height:20px;
background-color:#fff;border:0px; width:500px;overflow-y:auto;resize: none;}
//js 改变大小的方法
function text_readonly(){
	var mc = document.getElementById("text_content");
	if(mc != null && mc.value.length>0){
  		mc.rows = (mc.scrollHeight/20+2);
  	}
}
//text文本 怎么放内容看各种语言
<textarea class="text_readonly" disable="true" id="text_content" name="text_content" rows="4">
Assuming you have the Globalize
 plugin installed, the first thing you
 llneed to do is to generate its migration
 fileIf you want data for a full</textarea>
//在文本下调用即可
text_readonly()
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值