JQuery / on()并且在函数中不存在元素

时间:2021-03-22 20:11:03

I have this piece of code:

我有这段代码:

$(".tabs__nav[data-tab-id='2'").on('click', function (e) {
    $(this).off();
    var projects = [];
    $('.project').each(function () {
        var detail = new _detailMozaik2.default($(this));
        detail.init();
        projects.push(detail);
    });
});

'.project' items are main problem, cause these items appear after clicking on tab - Nette snippet (ajax) - items not exist before jQuery inits the on() function.

'.project'项目是主要问题,导致这些项目在单击选项卡后出现 - Nette片段(ajax) - 在jQuery进入on()函数之前项目不存在。

How to edit code, or what jQuery function have to use? Thanks

如何编辑代码或jQuery函数必须使用?谢谢

1 个解决方案

#1


0  

The problem is that .projects from other tabs still apear because they have the .project class anyway.

问题是来自其他标签的.project仍然是apear,因为它们仍然有.project类。

Start your JQuery with your target tab

使用目标选项卡启动JQuery

$(e.target).find('.project').each(function () {
  var detail = new _detailMozaik2.default($(this));
  detail.init();
  projects.push(detail);
});

#1


0  

The problem is that .projects from other tabs still apear because they have the .project class anyway.

问题是来自其他标签的.project仍然是apear,因为它们仍然有.project类。

Start your JQuery with your target tab

使用目标选项卡启动JQuery

$(e.target).find('.project').each(function () {
  var detail = new _detailMozaik2.default($(this));
  detail.init();
  projects.push(detail);
});