好久好久好久没有写过博客了。今天继续积累一点点吧。
如何让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代码设置其高度。