jQuery Autosize plugin on dynamically added textarea elements

为君一笑 提交于 2019-12-22 17:45:55

问题


Hi :) I'm using jQuery Autosize plugin to resize some of my textarea elements dynamically. Everything is good but the problem is that when I add some textarea elements to the DOM dynamically, the autosize thing no longer works.

I initialize the plugin like so:

$(document).ready(function () {
        $('textarea').autosize();
    });

I tried to enable the plugin for my dynamically added textareas like:

myDynamicallyAddedTextarea.autosize();

Unfortunately, nothing happened. Can anybody help me with this?


回答1:


sorry I can't comment yet, where are you adding this textarea at? can you post some of the code around the dynamic generation so that I can see when this stuff is getting called?

according to the docs, all you have to do is something like this for dynamically added elements...

function addTextArea() {
  $(body).append($('<textarea class="test" />'));
  $('.test').autosize();
});

//somewhere in code, but must be after the autosize plugin js has loaded
addTextArea();


来源:https://stackoverflow.com/questions/25410696/jquery-autosize-plugin-on-dynamically-added-textarea-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!