Html代码部分:
<div class= "con-info order-info-con1 ">
<p class="con-tit con-se-tit con-tit-items">备注: </p>
<div class="con-msg order-comment-div">
<textarea class="comment-textarea" rows="" cols="" th:text="${cretInfo.cComment}" disabled="disabled"></textarea>
</div>
</div>
Css代码部分:
.info-textarea {
border: 0px;
background-color: white;
width: 514px;
height: 125px;
resize: none;
text-indent: 25px;
}
JavaScript代码部分:
//textarea高度随文本内容变化,且不出现滚动条
$('textarea').each(function () {
this.setAttribute('style', 'height:' + (this.scrollHeight) + 'px;overflow-y:hidden;');
}).on('input', function () {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});
最终效果: