function autoTextAreaHeight(obj) {
obj.style.height = obj.scrollTop + obj.scrollHeight + 'px';
}
$(function(){
var infoObj = $('#content');
infoObj.on('input', function(){
autoTextAreaHeight(infoObj[0]);
});
});
通过以上代码实现了textarea随文本内容高度自适应的功能,但是现在有个问题是我只是水平输入的情况下,敲一个字符,textarea的高度会增加一行,我打印了一下数据,是scrollHeight的值在不断的增加,不知道是为何,请教高手帮忙解答一下,谢谢。
textarea
的padding
你去掉了吗?