简体   繁体   English

动态添加的textarea元素上的jQuery Autosize插件

[英]jQuery Autosize plugin on dynamically added textarea elements

Hi :) I'm using jQuery Autosize plugin to resize some of my textarea elements dynamically. 嗨:)我正在使用jQuery Autosize插件来动态调整一些textarea元素的大小。 Everything is good but the problem is that when I add some textarea elements to the DOM dynamically, the autosize thing no longer works. 一切都很好,但是问题是当我向DOM动态添加一些textarea元素时,自动调整大小功能不再起作用。

I initialize the plugin like so: 我像这样初始化插件:

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

I tried to enable the plugin for my dynamically added textareas like: 我试图为我的动态添加的textareas启用插件,例如:

myDynamicallyAddedTextarea.autosize();

Unfortunately, nothing happened. 不幸的是,什么都没有发生。 Can anybody help me with this? 有人可以帮我吗?

sorry I can't comment yet, where are you adding this textarea at? 抱歉,我无法发表评论,您在哪里添加此textarea? 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM