在jquery命令链中再次调用子上下文中的jquery

Call jquery in a subcontext again in jquery command chain

本文关键字:jquery 调用 上下文 命令      更新时间:2023-09-26

有可能这样做吗?

jQuery(selector).jQuery(subselector).command(....)

我的代码是这样的:

$(' .species')
.filter(function () { return !$(this).data('hidden_code_ready'); }
.wrapInner('<span class="species_info" />')
.append('<a href="" class="show_species"></a>')
.data('hidden_code_ready', true)

现在,对于这些匹配的元素(.species)中的每一个,我都想在.show_species中安装点击处理程序

$('.show_species',
    $(' .species')
    .filter(function () { return !$(this).data('hidden_code_ready'); }
    .wrapInner('<span class="species_info" />')
    .append('<a href="" class="show_species"></a>')
    .data('hidden_code_ready', true)
).click(...);

但这真的很尴尬。有没有可能做这样的事情:

$(' .species')
.filter(function () { return !$(this).data('hidden_code_ready'); }
.wrapInner('<span class="species_info" />')
.append('<a href="" class="show_species"></a>')
.data('hidden_code_ready', true)
.jQuery('.show_species').click(....);

最好也在jQuery 1.3.2中工作。谢谢

关闭!该函数被称为.find(),而不是jQuery:

$('.species')
    .filter(function () { return !$(this).data('hidden_code_ready'); }
    .wrapInner('<span class="species_info" />')
    .append('<a href="" class="show_species"></a>')
    .data('hidden_code_ready', true)
    .find('.show_species').click(....);