textarea 高度自适应
页面代码
<div class="form-group"> <label class="col-sm-3 control-label"><span style="color: red">*</span>模板内容:</label> <div class="col-sm-8"> <textarea id="content" rows="5" name="content" class="form-control" type="text" th:required="true" maxlength="1000"></textarea> </div> </div>
jquery代码
$('#content').on('input', function(e) { $(e.target).css('height', 'auto').css('height', this.scrollHeight + 'px'); //$(this).css('height', 'auto').css('height', this.scrollHeight + 'px'); });
参考资料: