textarea高度随文本内容变化,且不出现滚动条

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';
});

最终效果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值