问题
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