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';
});
最終效果: