是否可以使用 jquery 在点击中进行点击

is it possible to make an on click in an on click using jquery

是否可以在这样的点击中进行点击:

$(game.imageContainer).on('click', function(event) {
    var matchingClasses = true;
    $(game.differenceClass).on('click', function(event) {
        var matchingClasses = false;
    });

    if(matchingClasses){
        playwrong();
    }
});

更新: 我想要完成的是以下内容: 我有一个层(game.imageContainer),上面有小 div(game.differenceClass)。如果 game.imageContainer 被点击,我需要知道 game.differenceClass 是否也被点击。如果是的话就不应该玩错了()。

编辑:关注您的新评论:

if as wel the imagecontainer as the differenceclass is clicked then it should not playwrong(). if only the imagecontainer is clicked it should playwrong()

$(game.imageContainer).on('click', function (event) {
    if(event.target !== this) return;
    playwrong();
});

旧答案

所以委托事件而不是使用相关的 class 来丢弃选择器,如果 game.differenceClass 是一个字符串:

$(game.imageContainer).on('click', '*:not('+game.differenceClass+')', playwrong);

或使用对象:

$(game.imageContainer).on('click', function (event) {
  if ($(event.target).closest(game.differenceClass).length) return;
  playwrong();
});