用于ajax加载内容的jQuery选择器

时间:2016-08-05 12:58:23

标签: javascript jquery ajax

我使用过这个库: http://www.jacklmoore.com/autosize/

为了使用它我应该使用如下语法:

autosize($('textarea#description'));

或任何其他javascript选择器。 但我的textarea由ajax加载而且无法正常工作。

是否有其他选择器可以使用ajax元素? 谢谢

1 个答案:

答案 0 :(得分:1)

只需将jquery选择器包裹在其周围,然后使用.find()缩小范围。

$.ajax({...}).done(function(responseHTML){
    // depending on what the function is doing you may need to append it to the body first.
    $(responseHTML).appendTo('body'); // or wherever you want to put it
    $textarea = $(responseHTML).find('#description');
    autosize($textarea);
});
相关问题