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

来源:互联网 发布:琉璃神社最新域名 编辑:程序博客网 时间:2024/05/28 15:27

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

如何让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为kindeditoreditor.edit.setHeight(autoheight);


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


希望能给你提供帮助。

0 0
原创粉丝点击