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

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

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

解决方案如下:

textarea解决方案:

html:

css:

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

js:

$('textarea').each(function(){
	$(this).bind('input propertychange', function() {
		this.style.height=this.scrollHeight+'px'
	}).trigger("input");
});

kindeditor解决方案:

html:

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代码设置其高度。


希望能给你提供帮助。

你可能感兴趣的:(java,web)