jQuery在动态添加的textarea元素上自动调整插件 [英] jQuery Autosize plugin on dynamically added textarea elements
问题描述
嗨:)我正在使用 jQuery Autosize 插件动态调整我的一些textarea元素。一切都很好,但问题是,当我动态地向DOM添加一些textarea元素时,自动调整大小的东西不再起作用。
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.
我像这样初始化插件:
$(document).ready(function () {
$('textarea').autosize();
});
我尝试为动态添加的textareas启用插件,如:
I tried to enable the plugin for my dynamically added textareas like:
myDynamicallyAddedTextarea.autosize();
不幸的是,什么都没发生。任何人都可以帮我这个吗?
Unfortunately, nothing happened. Can anybody help me with this?
推荐答案
抱歉我还不能发表评论,你在哪里添加这个textarea?你可以在动态生成周围发布一些代码,以便我可以看到这些东西何时被调用?
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();
这篇关于jQuery在动态添加的textarea元素上自动调整插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!