简体   繁体   English

jQuery选择器以加载Ajax内容

[英]jQuery selector for ajax loaded content

I have used this library: http://www.jacklmoore.com/autosize/ 我已经使用了这个库: http : //www.jacklmoore.com/autosize/

and in order to use it I should use syntax like below: 为了使用它,我应该使用如下语法:

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

or any other javascript selector. 或任何其他JavaScript选择器。 But my textarea loaded by ajax and it is not working. 但是我的textarea由ajax加载,无法正常工作。

Is there any other selector that works with ajax elements? 是否还有其他可用于ajax元素的选择器? Thank you 谢谢

Just wrap the jquery selector around it and use .find() to narrow it down. 只需将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);
});

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

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