Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Eventlistener的多个筛选类_Javascript_Jquery - Fatal编程技术网

Javascript Eventlistener的多个筛选类

Javascript Eventlistener的多个筛选类,javascript,jquery,Javascript,Jquery,我正在尝试创建一个基于过滤某些类的eventlistener。我有一些有.product-group-5,从中我需要那些有.name 我已经创造了这个,它的工作 jQuery(".product-group-5").click(function () { if (jQuery(this).is(".name")) { // do something } }); 现在我需要过滤掉这个脚本中的另一个类。另一个,但我无法这样做 我尝试了下

我正在尝试创建一个基于过滤某些类的eventlistener。我有一些
.product-group-5
,从中我需要那些有
.name
我已经创造了这个,它的工作

jQuery(".product-group-5").click(function () {
    if (jQuery(this).is(".name")) {
    // do something
   }
});
现在我需要过滤掉这个脚本中的另一个类
。另一个
,但我无法这样做
我尝试了下面提到的脚本,但它不起作用

jQuery(".product-group-5").click(function () {
    let anotherThis = this;
    if (jQuery(this).is(".name ")) {
        if (jQuery(anotherThis).not(".another")) {
            // do something
        }
    }
});
html结构是这样的

<div class="someClass5 name product-group-5 ">I want to watch this click
</div>
<div class="someClass4 name product-group-1 ">not this
</div>
<div class="someClass3 name product-group-5 ">not this
</div>
<div class="someClass5 name product-group-5 another" style="display: block;"> And exclude this
</div>
我想看这个点击
不是这个
不是这个
并排除这一点

请帮帮我。

我想你要找的是:

$('.product-group-5.name')。不是('.other')。单击(函数(){
log('Clicked id:',this.id);
})
。另一个{margin:2em 0}

我想看这个点击
并排除这一点
我想看这个点击

我想你想要的是:

$('.product-group-5.name')。不是('.other')。单击(函数(){
log('Clicked id:',this.id);
})
。另一个{margin:2em 0}

我想看这个点击
并排除这一点
我想看这个点击

这是一个纯js示例,以备您需要

让htmlist=document.querySelectorAll(“div.someClass5:not(.other)”)
for(让htmlList的htmlElement){
HtmleElement.addEventListener('单击',()=>{
log('单击此处')
})
}
我想看这个点击
不是这个
不是这个
并排除这一点

这是一个纯js示例,以备您需要

让htmlist=document.querySelectorAll(“div.someClass5:not(.other)”)
for(让htmlList的htmlElement){
HtmleElement.addEventListener('单击',()=>{
log('单击此处')
})
}
我想看这个点击
不是这个
不是这个
并排除这一点

OP说他们有不止一个<代码>查询选择器
仅返回第一个found@Carlos1232谢谢你的回复。我已经编辑了我的问题,使我的场景更清晰。@Imraan Oh gotcha,我做了另一次编辑,以便将其保存在纯js中。OP说他们有多个问题<代码>查询选择器
仅返回第一个found@Carlos1232谢谢你的回复。我已经编辑了我的问题以使我的场景更加清晰。@Imraan Oh gotcha,我做了另一次编辑以使它保持在纯js中。