如何让textarea、kindeditor的高度自适应呢?

好久好久好久没有写过博客了。今天继续积累一点点吧。

如何让textarea、kindeditor的高度自适应呢?

解决方案如下:

textarea解决方案:

html:

<textarea id="mark"></textarea>

css:

#mark{width:100%;max-height:200px;resize:none}

js:

$('textarea').each(function(){
<span style="white-space:pre">	</span>$(this).bind('input propertychange', function() {
<span style="white-space:pre">		</span>this.style.height=this.scrollHeight+'px'
	}).trigger("input");
});

kindeditor解决方案:

html:

<textarea id="mark" ></textarea>

css:

#mark{width:100%;max-height:400px;resize:none}
js:

var autoheight=editor.edit.doc.body.scrollHeight;//此处的editor为kindeditor
editor.edit.setHeight(autoheight);


注意:要实现高度自适应,请务必在textarea、kindeditor赋值成功后调用相应的js代码设置其高度。


希望能给你提供帮助。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值