扩展textarea onload不会扩展HTML

时间:2020-04-17 12:55:17

标签: javascript html

我设法使我的textarea字段在输入时增加和缩小。但是,如果您这里的内容已经超过一行,那么它不会自动加载为多行。

有什么想法吗?或提示?谢谢

$(document)
.on('focus.autoExpand', 'textarea.autoExpand', 'change.autoExpand',  function(){

    var savedValue = this.value;
    this.value = '';
    this.baseScrollHeight = this.scrollHeight;
    this.value = savedValue;
})
.on('input.autoExpand', 'textarea.autoExpand', 'change.autoExpand',  function(){
    var minRows = this.getAttribute('data-min-rows')|0, rows;
    this.rows = minRows;
    rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 16);
    this.rows = minRows + rows;
});

0 个答案:

没有答案
相关问题