jQuery选择器中的AND和OR的组合 [英] A combination of AND and OR in jQuery selectors

查看:216
本文介绍了jQuery选择器中的AND和OR的组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jQuery选择器具有以下语法:

I have a jQuery selector with following syntax:

$('input[type=image]').not('.xyzClass').click(function{
    //some functionality
});

因此,这为所有类型为image的组件添加了特定的点击功能, xyzClass

So this puts a specific click functionality for all the components which are of type image and does not have class xyzClass.

*****我已修改问题以反映最新更改,以下一些答案对于先前版本是正确的,但对于修改的版本可能不正确。抱歉。

*****I have modified the question to reflect latest changes, some of the answers below are correct for previous version but may not hold correct for modified version. Apologies for that.

我们需要一个OR条件与类条件。这样
任何具有类型为image的输入组件应选择IF

We need an OR condition with class condition. Such that Any component which is "input" having type as image, should be selected IF


  1. 类不是 xyzClass

  2. id包含字符串 someIdString

  1. class is not xyzClassOR
  2. id contains string someIdString


    您能帮助修改现有的选择器吗?

Could you please help with the modification in existing selector?

干杯。

推荐答案

更新的答案

$('*:not(.xyzClass)[id*=containsThisValue]')

原始答案

function someSpecificFunctionality() {
}

$(els)

.click(someSpecificFunctionality)
.data('someSpecificFunctionality', true)


$(els).filter(function() {

    return 
        $(this).not('.xyzClass') && 
        $(this).data('someSpecificFunctionality') == true

});

这篇关于jQuery选择器中的AND和OR的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆